-
Help for a newbie?
Hi guys.
I am new to C++ programming, and i would like a bit of help. My compiler is saying that "m" is 'not declared in this scope'in this code:
Code:
#include <iostream>#include <math.h>
using namespace std;
int main() {
cout<<"you stand in a clearing in the forest, North of you is a house with an open letterbox in front of it and a locked gate beside said letterbox. To the South and West are a mass of brambles. To the East is a path through the trees.\n";
cin.get();
char a;
{cin>>a;
cin.ignore();
if (a==m);{
cout<< "yes";}
cin.get();
}
}
Where have i gone wrong?
-
Line 9 does a test "a==m" (I'm using double quotes simply to contain text). There is no variable named m anywhere, hence the compiler's complaint. If you want to compare a with the character 'm', the test needed is "a == 'm'" (note the single quotes around the m).
Also note that, on line 9, you have a misplaced semi-colon. Because of that, even if you get the code to compile, the string "yes" will always be written to cout, regardless of results of the test.
-
Thank you very much. It is fixed now.
-
You seriously need to learn how to format your code properly: IP Banned - GIDNetwork
Also, there should be no semicolon after the if statement.