My code is running correctly, only I'm not sure why I'm having to press "ENTER" when the user gets the answer wrong and loops back around for the same hint. I would like for it to say, "That is incorrect. Please try again." and the user answers right there instead of having to repeat the hint.
#include <iostream> //needed for cout and cin
#include <vector> //needed for vectors
#include <string> //needed for strings
#include <ctime> //needed for time
#include <cstdlib> //needed for srand
usingnamespace std;
int main ()
{
cout << "Color-me-Rad Guessing Game! \n" << endl;
cout << "Lets play a game!\n" << endl;
cout << "Guess the color using only the hint that is given to you." << endl;
cout << "You only have three tries! GOOD LUCK! \n" << endl;
//declarations
vector <string> Colors;
vector <string> Hints;
int number = 0;
int option = 0;
int guessCount = 1;
constint guesses = 3;
string answer, color;
Colors.push_back("red");
Colors.push_back("yellow");
Colors.push_back("purple");
Colors.push_back("blue");
Colors.push_back("green");
Colors.push_back("orange");
Hints.push_back("\nThe color of Ariel's hair in Disney's The Little Mermaid: ");
Hints.push_back("\nThe most common color of a glass of lemonade: ");
Hints.push_back("\nMixing blue and red gives you this color: ");
Hints.push_back("\nThe color of nobility, calmness, and serenity: ");
Hints.push_back("\nThis is the color of the forest: ");
Hints.push_back("\nThe color of the sunset: ");
srand((unsigned) time(NULL));
number = rand();
option = number % 6;
do{
number = rand() % Colors.size();
guessCount = 1;
for (unsignedint i = 0; i < guesses; ++i){
cout << Hints.at(number);
getline(cin, color);
cin.clear();
if (color == Colors.at(number)){
cout << "Good Job!";
i = guesses;
}
else {
cout << "That is incorrect. Please try again.";
getline(cin, color);
cin.clear();
guessCount++;
}
if (guessCount == 4){
cout << "Good try, but none of your answers were correct"
<< "\nThe correct answer is " << Colors.at(number) << "\n" << endl;
}
}
cout << "\n\nDo you want to play another round==> ";
getline(cin,answer);
} while (answer == "yes, Yes, Y, YES");
cout << "Thank you for playing. GOOD BYE!" << endl;
return 0;
}