I made a text based game where the player tries to guess a pre set number. That works fine. At the end there is a 'want to play again'? type thing. The main code is in a while loop so that should wrok. It did. Then I added some other stuff. An error message, which sould be if again doesn't equal upper or lower case y or n, it makes you try again. Instead, it always takes me to the error message and even when I enter upper or lower case n or y, it repeats the message. Before that, even the'y's would end the program, not restart it. Any help would be nice.
//Guess my number
//An originalish game by Calvin
#include<iostream>
#include<windows.h>
#include<cstdlib>
#include<ctime>
#include <string>
usingnamespace std;
string again;
int guess = 0; //this is the guess
constint numb = 8; //this is the number that try to guess
int main()
//start of main int
{
//its in a wile so they can play again
while (again == "y" || "Y")
//start of while loop
{
cout << "Hello, and wellcome to 'Guess my Number'! I am your host, CPU, and you have \nthree trys to guess my munber. It is between 1 and 10." << endl;
cout << "\nGuess number 1: ";
cin >> guess;
if (guess == numb) //first guess if
cout << "\nCorrect! Congratulations!" << endl;
else
{ //start of else 1
cout << "I am sorry, that is incorrect. Please try again." << endl;
cout << "\nGuess number 2: ";
cin >> guess;
if (guess == numb)//third guess if
cout << "\nCorrect! Congratulations!" << endl;
else
{ //start of else 2
cout << "I am sorry. Please try again." << endl;
cout << "\nFinal guess: ";
cin >> guess;
if (guess == numb) //third guess if
cout << "\nCorrect! Congratulations!" << endl;
else
cout << "I am sorry. That was incorrect." << endl;
} //end of else 2
} //end of else 1
cout << "\nDo you want to play again? (y/n): ";
cin >> again;
if (again == "n")
break;
else
{
if (again != "n" || "y")
{
while (again != "n" || "y")
{cout << "Error. Please enter a valid answer.\n";
cin >> again;}}}
} //end of while loop
cout << "Thank you for playing. Please come again!\n" << endl;
cin.get();
return 0;
} //end of main int