I'm fairly new to C++, and as a learning exercise I'm making a simple 'quiz game' in which the user needs to input the correct answer in order to proceed to the next question. They can also input 'Help', which prompts the program to print a small hint.
Here's the code so far:
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{string prima, secunda, tertia;
cout << "How many were going to St. Ives?\n";
cin >> prima;
while (prima !="Help" || prima!="One") {
cout <<"Sorry, that's not the right answer. Would you like some help?\n";
cin >> prima;}
while (prima=="Help") {
cout << "Believe me when I say you don't need to do the math.\n";
cin >> prima;}
if (prima=="One") {
cout <<"Nice one! Now lets move on to question two, shall we?\n";}
system("PAUSE");
return EXIT_SUCCESS;
}
I've got two main problems at the moment:
1. There seems to be something wrong with
Code:
while ((prima !="Help") || (prima!= "One")) {
I've tried writing it out in a number of different ways, substituting the '||" for 'or', or putting 'prima !=' before both conditions, but the program only ever acknowledges the first condition (ie. That the 'help' command wasn't entered). If I enter 'One', I get the same response loop as if I'd entered any other string value that isn't 'Help'. Would someone mind correcting me so that the program will respond to both conditions?
2. Is there any way to re-initialize a while loop after it's been executed? Right now, if a user inputs one (or many) incorrect responses, then inputs "Help", and after reading the hint, enters another wrong answer, the program ends. I'd like to make it so that the "Sorry, that's the right answer..." loop occurs whenever a user supplies an incorrect response, even if the loop has occurred and ended before.
Thanks so much in advance for your help; I really appreciate this, and hopefully it'll be a step on the way to becoming a fully-fledged programmer one day.