Line 9-11: These are uninitialized strings.
Line 13: You're missing a close quote.
Line 18,21,23: You're comparing to uninitialized strings. Either give lines 9-11 values, or compare to quoted strings.
Line 25: Several problems with your
else
1) C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example:
if (ans == 'Y' || 'y')
evaluates as
if ((ans == 'Y') || ('y'))
('y')
always evaluates to 1 (
true
), therefore the if statement is always true.
2) You want
and
not
or
here.
3)
else
does not take a condition clause. You could have said
else if
, but the condition is really not required since you've already determined job is not a warrior and not a thief and not a knight.
Lines 19-27: This is a single block which is executed only if job is "warrior". Line 21-26 are misplaced. They should be moved to after line 27.
Lines 20,22,24: You're missing the ; at the end of the statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <string>
using namespace std;
int main ()
{ string name;
string job;
cout <<"Hello Adventure what is your name?" ;
getline (cin, name) ;
cout <<"Welcome," << name << "Are you a warrior, a thief, or a knight?";
getline (cin, job);
if (job == "warrior")
{ cout <<"Ah so you are the mighty Warrior.";
}
else if (job=="knight")
cout <<"Not bad, the brave Knight.";
else if (job=="thief")
cout <<"Oh no a sneaky thief I see!";
else
cout <<"Please choose Knight, Warrior, or Thief to select your class";
}
|