Hello. I have to write a program that lets the user guess a number from a random number and say if its too high/low/correct.
However, the part I am stuck on is that after the user guesses it correctly, I need to have it ask if the user wants to play again, whereas the user enters y for yes and n for no.
Here is what my code is so far:
I am getting an empty character constant in regards to this line:Code:#include <iostream> #include <cstdlib> using namespace std; int main () { int a; int b; srand(a); a = rand()%1001; cout << "I have a number between 1 and 1000." << endl; cout << "Can you guess my number?" << endl; while (1) { char again=''; do { cout << "Please type your first guess." << endl; cin >> b; if (b > a) cout << "Too high. Try again" << endl; if (b < a) cout << "Too low. Try again." << endl; } while (b != a); cout << "Excellent! You guessed the number!" << endl; while (again != 'y' || again != 'n') { cout << "Would you like to play again (y or n)?" << endl; cin >> again; } if (again == 'n') break; } return 0; }
How do I go about fixing it?Code:char again='';