#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
//Types and Arrays
string word[16] = {"GOLDFISH", "COMPUTER", "ANONYMOUS", "JACKET", "SHARP", "SERVICE", "EFFORT", "CHARACTER", "CHANGE", "WITHOUT", "PRODUCT", "UNFOLDS", "MUSIC", "MOMENT", "LIFETIME", "PROVIDE"};
char guess[50];
static const char Y= 'Y';
static const char N= 'N';
char ans;
// Functions
int instructions();
int game();
int main()
{
cout << "\tWelcome to Word Jumble By Khoanyneosr!\n";
cout << "\nWould you like to see the instructions?"
<< "\n\t1) Yes = Y"
<< "\n\t2) No = N\n- ";
bool rep= true;
while (rep) {
cin >> ans;
cin.ignore(1, ' '); // Figure this out
switch (toupper(ans)) {
case Y:
cin.clear();
cin.sync();
instructions();
rep= false;
break;
case N:
cin.clear();
cin.sync();
game();
rep= false;
break;
default:
cout << "\n\nInvalid input.\n\n- ";
cin.clear();
rep= true;
break;
}
}
return 0;
}
int instructions()
{
system("cls");
cout << endl << endl << "\tINSTRUCTIONS" << endl;
cout << endl << "1 - You will be presented with a word. Your job is to guess it." << endl;
cout << endl << "2 - At the beginning of the game your given 10 points." << endl;
cout << endl << "3 - You will be given 1 hint. Everytime you have to revisit\nthe hint 1 point will be deducted." << endl;
cout << endl << "4 - For everytime you guess wrong 1 point will be deducted." << endl;
cout << endl << "5 - When your point value reaches 0, the game is over." << endl;
cout << endl << "You can exit at anytime by pressing Q." << endl;
cout << endl << endl << "\tGood Luck!" << endl << endl << endl;
system("pause");
return game();
}
int game()
{
cout << endl << "what is your guess?\n- ";
cin.getline(guess, 50);
cout << endl << guess << endl;
return 0;
}
That's my code. I need to know how, at the very beginning, how to fix the fact that for every character that is "invalid" it repeats...
Invalid input.
-
Go ahead and compile it if it doesn't make sense. Thanks in advance.