So I have this school project and I am attempting to make a history game. However whenever I get to stage 3, it causes a repeat with the answer. Any ideas?
#include <iostream>
#include <string>
usingnamespace std;
bool gameRunning = true;
int main()
{
while (gameRunning == true)
{
cout << "Welcome to World History adventures! To play press the \" p \" . To quit at any time press \" esc \" . Please enjoy the adventure! Lead writer: Locke Thornburge, Lead Programmer Matthew Byrd" << endl;
string startD;
cin >> startD;
if (startD == "p")
{
cout << "You want to start your civilization. You come across a river vally. What do you do? (s = settle, l = leave) \n";
string secondD;
cin >> secondD;
if (secondD == "s")
{
cout << "you settle a wonderous civilization! However it appears to be missing something, what? (Hint: Mr. Barhams website. Alphabetical order)\n" << endl;
string thirdD;
cin >> thirdD;
if (thirdD == "Arts and archatectiure, cities, complex relieions, organized government, writing\n")
{
cout << "lol" << endl;
string fourD;
cin >> fourD;
if (fourD == "stop")
{
cout << "dead" << endl;
}
}
}
if (secondD == "l")
{
cout << "you die of dehydration idiot" << endl;
}
}
}
}
Line 28: You have an embeded \n in the string you're comparing. cin reads until it finds a \n not passing it to the input string. You will never get a valid comparison here. Remove the \n from the comparison string.
lol this game is ... interesting. i think in line 28 it would be impossoble to guess that. also u spelled arch. wrong. the person before me gave you the error.
also dont type long lines. line 15 is so long. split it into 2 lines.
Thanks, yeah I think the clues need some work but this is still pre - alpha technically. anyway thanks for the advice! I tired putting this out to a few friends while I am working on it and they are getting "Project1 (1).exe - System Error
The program can't start because MSVCP120D.dll is missing from your computer. Try reinstalling the program to fix this problem." Any ideas?
Also still getting this when typing in the answer "Arts and archatectiure, cities, complex relieions, organized government, writing":
Welcome to World History adventures! To play press the \" p \" . To quit at any time press \" esc \" . Please enjoy the adventure! Lead writer: Locke Thornburge, Lead Programmer Matthew Byrd"Welcome to World History adventures! To play press the \" p \" . To quit at any time press \" esc \" . Please enjoy the adventure! Lead writer: Locke Thornburge, Lead Programmer Matthew Byrd"
Project1 (1).exe - System Error
The program can't start because MSVCP120D.dll is missing from your computer. Try reinstalling the program to fix this problem.
Did you build your program in release mode or debug mode?
Also still getting this when typing in the answer "Arts and archatectiure, cities, complex relieions, organized government, writing" [...]
That's because you're using the extraction operator >>. It will stop reading from cin as soon as it hits a space.
Still getting the same error in release mode and how FG would I go about keeping the answer without having spaces? Is there another operator I can use?
Maybe it's a problem with linking dynamic libraries vs static libraries. Honestly, I don't use Visual Studio much, so I don't know...
.
Instead of cin >> secondD; use getline(cin, secondD);
It just restarts the game as if there was no more content, I have updated it since then not sure what is going on there:
#include <iostream>
#include <string>
using namespace std;
bool gameRunning = true;
int main()
{
while (gameRunning == true)
{
cout << " !*PRE - ALPHA EXPECT SPELLING ERRORS AND GLITCHES*! Welcome to World History \n adventures! To play press the \" p \" . To quit at any time press \" esc \" . Please enjoy the adventure! Lead writer: Locke Thornburge, Lead Programmer Matthew Byrd" << endl;
string startD;
cin >> startD;
if (startD == "p")
{
cout << "You want to start your civilization. You come across a river vally. What do you do? (s = settle, l = leave)" << endl;
string secondD;
cin >> secondD;
if (secondD == "s")
{
cout << "you settle a wonderous civilization! However it appears to be missing something, what? (Hint: Mr. Barhams website. Alphabetical order (!*ALPHA*! the answer is \"TEMP\")" << endl;
string thirdD;
getline(cin, thirdD);
if (thirdD == "Arts and architecture, cities, complex religions, organized government, social classes, writing")
{
cout << "Your civilization's culture is booming! Insert a random number to have a event occur!" << endl;
string fourthD;
cin >> fourthD;
if (fourthD == "1")
{
cout << "Your civilization devlops a wonder of the world! Your citizens rejoice!" << endl;
}
else
{
cout << "Your civilizaion discovers gold mining! Your citizens suggest to use it for holy structures, however you could use this to trade with neighboring civilizations. What do you do? (r = holy structures, t = Trade with neighbors)" << endl;
}
}
}
if (secondD == "l")
{
cout << "you die of dehydration idiot" << endl;
}
Please post your code inside the [code][/code] tags. And it's not working because there is a '\n' left in the stream after using the extraction operator >>. You can add cin.ignore() before the getline.