/* function main begins program execution */
int main()
{
int guess;
int value;
bool quit = false;
srand((unsigned int)(time(NULL)));
while (quit != true)//Repeats game
{
cout<<"Welcome to the Random Number Game!\n";
cout<<"You will have 20 attempts per game to guess the number.\n";
cout<<"Good Luck & Have Fun!!!\n\n";
int i; //counter
value = rand() % 100 + 1; // Generate random numbers from 1 to 100
for(i = 1; i<=20 ; i++) //loop 20x
{
cout<<"number is" <<value<<endl;//line for testing
cout << "Try to guess the hidden number between 1 and 100: ";
cin >> guess;
cout << endl;
if (guess < value)
cout<<"Your guess is lower than the hidden number.\n\n";
else if (guess > value)
cout<<"Your guess is higher than the hidden number.\n\n";
else if (guess == value)
break;
}
if(guess == value)
{
value = rand() % 10 + 1;//generate random number from 1-10
switch(value) //Output cases for winning
{
case 1: cout<< "You have won the game congratulations!"<<endl;
break;
case 2: cout<< "Nooo you have beaten my game!"<<endl;
break;
case 3: cout<< "Luck is on your side today user you win this round!"<<endl;
break;
case 4: cout<< "I regret to inform you.....that you have won!"<<endl;
break;
case 5: cout<< "Your skills are superior to my program well done!"<<endl;
break;
case 6: cout<< "You have won the battle but not the war!"<<endl;
break;
case 7: cout<< "I will get you next time I promise!"<<endl;
break;
case 8: cout<< "Congratulations you are now the smartest person in the world!"<<endl;
break;
case 9: cout<< "Take your luck to Vegas and win some cash!"<<endl;
break;
case 10: cout<< "You are a genius...nuff said."<<endl;
break;
}
break;
}
else if(guess != value)
{
value = rand() % 10 + 1;//generate random number from 1-10
switch(value) //Output cases for Losing
{
case 1: cout<< "And what did you expect from such a substandard intelligence?"<<endl;
break;
case 2: cout<< "You have lost the game. Better luck next time."<<endl;
break;
case 3: cout<< "My granny could play this game better than you!"<<endl;
break;
case 4: cout<< "Get on my level user!"<<endl;
break;
case 5: cout<< "Such an easy game and yet you still managed to lose...."<<endl;
break;
case 6: cout<< "Do yourself a favor and delete this program from your files!"<<endl;
break;
case 7: cout<< "Surely you can do better than that."<<endl;
break;
case 8: cout<< "You will never beat the almighty microsoft!"<<endl;
break;
case 9: cout<< "Too bad you can't cheat at this game becasue it's random!"<<endl;
break;
case 10: cout<< "Please go back to Kindergarten and learn to count."<<endl;
break;
}
break;
}
else if(guess == value | guess != value)
{
value = rand() % 10 + 1;//generate random number from 1-10
switch(value) //Output cases for Continuing
{
case 1: cout<< "\nWould you like to continue? [Y/N] ";
break;
case 2: cout<< "\nTry your luck again? [Y/N] "<<endl;
break;
case 3: cout<< "\nYou think you can beat me again? [Y/N] "<<endl;
break;
case 4: cout<< "\nPlay again at your own risk? [Y/N] "<<endl;
break;
case 5: cout<< "\nChallenge me again user? [Y/N] "<<endl;
break;
case 6: cout<< "\nDon't quit now maybe you should try again? [Y/N] "<<endl;
break;
case 7: cout<< "\nQuit being a pansy and play again! [Y/N] "<<endl;
break;
case 8: cout<< "\nDon't give up now try again! [Y/N] "<<endl;
break;
case 9: cout<< "\nPlease play again I need you! [Y/N] "<<endl;
break;
case 10: cout<< "\nGive me another chance please? [Y/N] "<<endl;
break;
}
break;
}
I have gotten the conditions to execute properly but will end the program after doing a case instead of asking to play again and loop. Also how would i output the number of wins and losses?
You don't end if statements with "break;", this is likely causing some kind of issue in your running loop. In order to output the number of wins and loses you first have to keep track of them so make two more unsigned ints and increment them when appropriate.
I appreciate your help sir i changed my if statements to do while loops and set unsigned ints wins and losses to 0. Everything works correctly except both my winning and losing cases are being executed. Once again thank you for your help I can handle the rest!