Im very new to c++ and trying to write a simple game to learn some of the basic mechanics and i'm having trouble with my code,
How do I define the function WantToPlay so that when a player enters "yes" it replies fantastic, and "no" replies boooo?
My current code gives the error that WantToPlay must be of bool type, but i'm not sure how to use a boolean function to rectify it?
Thanks!
using std::cout;
using std::cin;
using std::endl;
using std::string;
string leader;
string WantToPlay;
int main()
{
std::cout << "Dungeon Master: Welcome to my dungeon, traveller! What is your name?" << std::endl;
cin >> leader;
cout << "Dungeon Master: Well hello, " << leader << " I have a little quest for you if you're interested?" << endl;
cout << "(Please enter ""yes"" or ""no"")" << endl;
cin >> WantToPlay;
if (WantToPlay = "yes")
cout << "Fantastic!" << endl;
else if (WantToPlay = "no")
cout << "boooo" << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire