I'm having a lot of trouble with a project for school. The project calls for me to create a random guessing game with three different levels. Each level should consist of a random number between 1 and 30. I have set my code to show between 1 and 5 for the purpose of seeing how well it works. The problem I'm having comes after the second correct guess because it seems that the third guess is the exact same as the 2nd guess. If you could help I'd greatly appreciate it seeing as this project is due in 2 days.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int number, guess;
number = rand () % 5+1;
for(int i=0;i<3;i++)// first level
{
cout <<"Please enter your guess: ";
cin>>guess;
/* loop through 3 attempts */
if (guess==number) {
cout<<"Good guess!\n";
break; }
else
cout<<"Please try again!\n";
if (i == 2)
return 0; // if failed 3 times, end program
}
int option, a;
number = rand () % 5+1;
bool finished = false;
while (!finished)
{
cout<<"Would you like to continue? \n";
cout<<"\n";
cout<<"[1] Yes \n"
<<"[2] No \n";
cin>>option;
switch(option)
{
case 1:
{
for(int i=0;i<3;i++)// second level
{
cout <<"Please enter your guess: ";
cin>>guess;
/* loop through 3 attempts at pin */
if (guess==number)
{
cout<<"Good guess!\n";
finished = true;
goto test3;
break;
}
else
cout<<"Please try again!\n";
if (i == 2)
return 0; // if failed 3 times, end program
} /* end password loop */
}
break;
case 2:
{
finished = true;
{
cout<<"Thanks for playing!";
}
return 0;
}
break;
test3:
int choice;
number = rand () % 10+1;
bool finished = false;
while (!finished)
{
cout<<"Would you like to continue? \n";
cout<<"\n";
cout<<"[1] Yes \n"
<<"[2] No \n";
cin>>choice;
switch(choice)
{
case 1:
{
for(int i=0;i<3;i++)// third level
{
cout <<"Please enter your guess: ";
cin>>guess;
/* loop through 3 attempts at pin */
if (guess==number)
{
cout<<"Good guess!\n";
finished = true;
break;
}
else
cout<<"Please try again!\n";
if (i == 2)
return 0; // if failed 3 times, end program
} /* end password loop */
}
break;
case 2:
{
finished = true;
{
cout<<"Thanks for playing!";
}
return 0;
}
break;
}
return 0;
}
}
}
}