#include <cstdlib>
#include <iostream>
#ifdef WIN32
#include <windows.h>
#endif
#include <clearscreen.h>
usingnamespace std;
int main()
{
int selectionFirst;
int selectionPrologue;
bool definitionPone;
cout << "\t\t\tHonors World History study helper v.1\n\n";
cout << "This program will ask you to select a chapter, then a section in that chapter, and then show each definition for five (5) seconds, then will ask you to give the vocabulary word.";
cout << "\n\nChoose the Chapter to study:\n\n";
cout << "1.) Prologue\n\n";
cout << "2.) Chapter 1";
cout << "\n\n";
cin >> selectionFirst;
if (selectionFirst == 1)
{
ClearScreen();
cout << "\nPlease choose the section you would like to study: \n\n";
cout << "1.) Section 1\n\n";
cin >> selectionPrologue;
if (selectionPrologue == 1)
{
ClearScreen();
cout << "A system for controlling society is... ";
cin >> definitionPone;
if(definitionPone == 'Government' or definitionPone == 'government')
{
cout << "great. Moving on.\n\n";
}
else
{
cout << "incorrect. Moving on.\n\n";
}
ClearScreen();
cout << "Form of government in which citizens rule and make laws directl rather than through representatives.";
}
}
system("PAUSE");
return 0;
}
Now don't mind the System("Pause") that makes it easier on me (for the moment).
My problem is right here:
1 2 3 4 5 6 7 8 9 10
cout << "A system for controlling society is... ";
cin >> definitionPone;
if(definitionPone == 'Government' or definitionPone == 'government')
{
cout << "great. Moving on.\n\n";
}
else
{
cout << "incorrect. Moving on.\n\n";
}
It is totally bypassing the if statement and going to the else. I took out the whole else statement for a test and the cout never showed up. Can you guys help?
hunter, though all previous posts were correct in the points they raised, none of them was complete.
As all of them said, you won't get the result you expect, if you try to read a string into boolean, so do as said and use string definitionPone;. Your string comparisons were incorrect too, though last posters fixed them, they never said anything about them. Use double quotes for strings and apostrophes for characters.
I also have some recommendations about doing a quiz program. I would separate the program from the questions (you can store questions in a simple XML file), because it would be possible to modify questions w/o recompiling the program and it could be reused with different questions later.
C++ has both || and or with the same meaning.
Notice that you can't use that operator like this: answer == "Government" || "government"
the right way of using it is answer == "Government" || answer == "government"
Thanks soo much guys (and gals?) You have been most helpful. sikac's post fixed my problem :D. Thanks again. I'll be sure to let you know of the final result ;)
/* Edit */
Okay, it works but i just tried to add another definition and its skippping the you are right message.
string defintionPtwo;
ClearScreen();
cout << "Form of government in which citizens rule and make laws directly rather than through representatives is... ";
cin >> defintionPtwo;
if (defintionPtwo == "Direct Democracy" or defintionPtwo == "direct democracy")
{
cout << "Thats correct! Moving on.";
int seconds = 1;
#ifdef WIN32
Sleep(seconds*3000);
#else
sleep(seconds);
#endif
}
else
{
cout << "Sorry, you are wrong. The correct answer was Direct democracy. Moving on.";
int seconds = 1;
#ifdef WIN32
Sleep(seconds*3000);
#else
sleep(seconds);
#endif
}
It goes right to the you are wrong even though the answer was right. Any ideas?