trying to write a text based game on day 1 of learning c++, no real background on programming so my debug skills are fairly weak.
Receiving an error on line 20 error C2065: 'Warrior' : undeclared identifier ( cClassType = Warrior )
I believe its because I'm using Warrior wrong, I thought to use quotes on Warrior but that brings a new slew of errors. I basically want to store cClassType as a string, Warrior, Mage, Cleric, etc. based on selection.
I've replaced the class type string selection to an int selection instead and got that to work, but would like to know what I'm doing wrong for reference. Can someone take a look? thanks!
1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5 int main()
6 {
7 //Declare variables as Blank
8 string cName = "";
9 string cClassType = "";
10 string cWarriorMsg = "Ahhh, strength, honor, and love to smash your opponents....strong choice";
11 //Output question for name
12 cout << "Enter your character's name and press Enter: ";
13 //stores character name
14 cin >> cName;
15 cout << "Hello, " << cName << endl << endl;
16 cout << "Welcome to the End of Days" << endl;
17 cout << "What role do you play in your life?" << endl;
18 cout << "Warrior, Assassin, Mage, Cleric?" << endl;
19 cin >> cClassType;
20 if( cClassType = Warrior )
21 {
22 cout << cWarriorMsg << endl;
23 }
24 else
25 {
26 cout << "Ahh that's okay weakling." << endl;
27 }
28 }
When the compiler tells you that it found an identifier it doesn't recognize, it means that you've used an identifier with no associated type-specifier or it's used after it was popped from the stack. Also, the comparison on line 20 should be changed to: if(cClassType == Warrior). If the c prefix denotes a class, be sure to overload the assignment operator to accept whatever type Warrior is.
You can give a variable a value at the point of declaration (initialization) or give it a value after its declaration (assignment).