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;

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 1CP
icon
Related questions
Question

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;

break,
goto B;
}
}
if (guess == rnum)
cout <<" Congratulation " << a << " You Have Done IT...!lla"<<endl;
switch (count)
{ case 7: cout <<" Your Score is 100 out of 100"<<endl;
break;
6: cout <<" Your Score is 85 out of 100" << endl;
case
5: cout <<" Your Score is 70 out of 100" << endl;
break;
case 4: cout <<"Your Score is 55 out of 100" << endl;
break;
case 3: cout <<" Your Score is 40 out of 100" << endl:
break;
case 2: cout <<" Your Score is 25 out of 100" << endl:
break;
case 1: cout<<" Your Score is 100 out of 100 " << endl:
break;
}
}
else
{
cout << " Sorry " << a<<" Bad Luck...!!Try Next Time "<<endl;
cout << " Want to Play More(y / n) :"<<endl;
cin >> ch:
if (ch == 'y' || ch == 'Y')
{
goto A;
else
{
cout<<" Thank you for participating "<<endl;
Sleep(10000);
exit();
}
break;
case 3: { cout << "==:
cout << "= Thank you for participating
cout << "===:
Sleep(10000);
exit();
=="<<endl;
=" << endl;
<<endl;
}
system("pause");
}
Transcribed Image Text:break, goto B; } } if (guess == rnum) cout <<" Congratulation " << a << " You Have Done IT...!lla"<<endl; switch (count) { case 7: cout <<" Your Score is 100 out of 100"<<endl; break; 6: cout <<" Your Score is 85 out of 100" << endl; case 5: cout <<" Your Score is 70 out of 100" << endl; break; case 4: cout <<"Your Score is 55 out of 100" << endl; break; case 3: cout <<" Your Score is 40 out of 100" << endl: break; case 2: cout <<" Your Score is 25 out of 100" << endl: break; case 1: cout<<" Your Score is 100 out of 100 " << endl: break; } } else { cout << " Sorry " << a<<" Bad Luck...!!Try Next Time "<<endl; cout << " Want to Play More(y / n) :"<<endl; cin >> ch: if (ch == 'y' || ch == 'Y') { goto A; else { cout<<" Thank you for participating "<<endl; Sleep(10000); exit(); } break; case 3: { cout << "==: cout << "= Thank you for participating cout << "===: Sleep(10000); exit(); =="<<endl; =" << endl; <<endl; } system("pause"); }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning