So I need to write a program where the user tries to guess a magic number. The only thing that I do not know how to do is set the max. amount of guesses to 5. This is what I have so far. Can someone please show me how to limit the user to 5 guesses? Thanks so much!
#include <iostream>
using namespace std;
int main()
{
int magic=6, guess;
do
{
cout <<"Guess the magic number. The number is anywhere between 0 and 9: \n";
cin >>guess;
if (magic == guess)
{
cout <<"You guessed right. \n";
}
else if (magic<guess)
{
cout << "You guessed too high.\n";
}
else
{
cout << "You guessed too low.\n";
}
}while (magic!= guess);
return 0;
}