0
crashing program
my program keeps crashing can you help? heres the code: #include<iostream> #include<stdio.h> int main() { char* a; using namespace std; cin>>a; if(a=="logan") { cout<<"granted"; } else{ cout<<"denied"; } return 0; }
5 Answers
+ 3
using namespace std;
needs to be in with all the header files, not inside main.
#include <iostream>
using namespace std;
int main() { }
+ 1
char can contain only one character. therefore it crashes I guess
+ 1
char* is a used to iterate through a character array, there is nothing wrong with what he has written here. It generates a compile error because of the header file being inside the main, c'mon guys.
0
I don't think u can input value for pointer .
- 2
hey mlg, use this code
#include<iostream>
#include<string>
using namespace std;
int main()
{
string mycode;
cout<<"enter code";
cin>>mycode;
//or use if(mycode=="Logan")
if (mycode.compare("Logan"))
cout<<"granted";
else
cout<<"denied";
return 0;
}