Rest of code in image / This is a bad programming style since it is using goto. // This is an spagetti code and not working. // Use function to display menu, and display game rules, // Use different color for text display. // fix it so it works any way you like. /* HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE); // Write 16 lines in 16 different colors. for (int color = 0; color < 16; color++) { SetConsoleTextAttribute (screen, color); cout << " Hello World!" << endl; Sleep(400); // Pause between lines to watch them appear } // Restore the normal text color) SetConsoleTextAttribute(screen, 7); */ #include #include using namespace std; int main() { //textbackground(WHITE); //textcolor(RED); system("cls"); char ch, a[20], ch2; int num = 100, rnum, guess, count, ch1, c = 0; cout << "**********************************************************"<> ch1; switch (ch1) { case 1: //system("cls"); cout << " General Description"<> ch2; if (ch2 == '*') { ch2 = '#'; goto C; } else goto D; break; case 2: //system("cls"); cout << "Enter Your Name : "; cin >> a; for (int i = 0; i <= 100; i += 20) { cout << "Loading " << i < 0) system("cls"); randomize(); rnum = random(num); cout << " Enter Your Guess : "; cin >> guess; count = 8; B: while (guess != rnum) { count--; if (guess > rnum) { cout << guess << " is High….!!!! " << " Now You Have "<< count <<" chance left "<> guess; goto B; } if (guess < rnum) { cout << guess << " is Low…!!! "<< " Now You Have " << count << " chance left"<> guess; goto B;
Rest of code in image
/ This is a bad programming style since it is using goto.
// This is an spagetti code and not working.
// Use function to display menu, and display game rules,
// Use different color for text display.
// fix it so it works any way you like.
/*
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
// Write 16 lines in 16 different colors.
for (int color = 0; color < 16; color++)
{
SetConsoleTextAttribute (screen, color);
cout << " Hello World!" << endl;
Sleep(400); // Pause between lines to watch them appear
}
// Restore the normal text color)
SetConsoleTextAttribute(screen, 7);
*/
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
//textbackground(WHITE);
//textcolor(RED);
system("cls");
char ch, a[20], ch2;
int num = 100, rnum, guess, count, ch1, c = 0;
cout << "**********************************************************"<<endl;
cout << "* Welcome To High / Low Game *" << endl;
cout << "**********************************************************" << endl;
cout << " Main Menu " <<endl;
cout << " 1. Rules " << endl;
cout << " 2. Play " << endl;
cout << " 3. Exit " << endl;
cout<< " Enter your choice(1 - 3) : " << endl;
cin >> ch1;
switch (ch1)
{ case 1: //system("cls");
cout << " General Description"<<endl;
cout << " The Computer picks a random number from 0 to 99.n You must try to guess the number."<<endl;
cout << " The Computer ask you to enter your guess.You have 8 chances to guess the number."<<endl;
cout << " The computer checks the number, if your guess isn less than computer’s numer than " << endl;
cout<< " it will show a messagen that your guess is lowand ask for higher number."<<endl;
cout << " If your guess is higher than the computer’s numbern than computer will show" << endl;
cout << " a message that your guess is high andn ask for lower number."<<endl;
cout << " If your guess is equal to the computer’s number, thann computer" << endl;
cout << " will print a message congratulating younand will ask you to play the game again or exit."<<endl;
cout << " If you are unable to guess the number than the computern " << endl;
cout << " will a sorry message and ask you to play the game again or exit."<<endl;
//D: cout << “nnn Press * to goto Main Menu : ”;
//cin >> ch2;
if (ch2 == '*')
{ ch2 = '#';
goto C;
}
else
goto D;
break;
case 2: //system("cls");
cout << "Enter Your Name : ";
cin >> a;
for (int i = 0; i <= 100; i += 20)
{ cout << "Loading " << i <<endl;
Sleep(100);
}
cout << "Hi "<< a << " !!!!";
A: if (c > 0)
system("cls");
randomize();
rnum = random(num);
cout << " Enter Your Guess : ";
cin >> guess;
count = 8;
B: while (guess != rnum)
{ count--;
if (guess > rnum)
{
cout << guess << " is High….!!!! " << " Now You Have "<< count <<" chance left "<<endl;
if (count == 0)
break;
cout << " Enter Your Guess Again : ";
cin >> guess;
goto B;
}
if (guess < rnum)
{
cout << guess << " is Low…!!! "<< " Now You Have " << count << " chance left"<<endl;
if (count == 0)
break;
cout << " Enter Your Guess Again : " <<endl;
cin >> guess;
goto B;
Step by step
Solved in 2 steps