// Randam Guessing Game 
#include <iostream>
#define NEWLINE "\n\n\n"
#include <cstdlib> // need to use rand() function
#include <ctime>

using namespace std;

/*void Start();
void GetResult();
void HighScore();



int a, b, chance, maxrand;
char difficultychoice, menuchoice, diffchoice;


void Start()
{
     a = 0;
     b = 0;
     chance = 0;
     maxrand = 0; */
     
int main ()
{
    srand((unsigned)time(0));
    
    int choice, result;
    
    
    
    while (choice != 6)
    {
    
   // cout<< "\tGuessing Game Program"; //Title of the Program
    cout<< NEWLINE;
    
    cout<< "\tMENU\n"; // Title
    cout<< "\t=====\n\n";
    cout<< "\t1. Guess the Number    [Range between 1 to 100.]\n"; 
    cout<< "\t2. Guess the Alpabet    [Range between A to Z.]\n";
    cout<< "\t3. Difficulty Level Game\n";
    cout<< "\t4. High Score [Current top score]\n"; // high score for both number and alphabet game
    cout<< "\t5. Credit\n"; // programmer detail
    cout<< "\t6. Quit    [Enter any key to exit program!]\n"; // Exit program
    cout<< NEWLINE;
    
    cout<< "\tSelect Menu ==> "; // user to input he or her choice of game
    cin>> choice;
    cout<< NEWLINE;
    
    switch (choice)
    {
           case 1:
                cout<< "\tGuess the Number\n"; // one of the selection choice that user has made
                cout<< "\t================\n\n";
                cout<< "\tInstructions:\n"; // list of instruction that user must follow
                cout<< "\t1. Guess the number based on the give range.\n"; //number range is depend on the programmer
                cout<< "\t2. You are allowed to make one guess at a time.\n";
                cout<< "\t3. Each game has 5 chance to guess the corrent number.\n"; // user is given 5 or more chance to guess the number
                cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                cout<< NEWLINE;
                cout<< "\tGood Luck to You!";
                cout<< NEWLINE;
                cout<< "\tPlease guess from 1 to 100. 5 chances left. What is the number?"; //use is ask to guess the number
                cout<< NEWLINE;
                
                break;
                
               // case 2:
                     
                    cout<< "\tGuess the Alphabet\n"; // one of the selection choice that use has made
                    cout<< "\t================\n\n";
                    cout<< "\tInstructions:\n"; // list of instruction that user must follow
                    cout<< "\t1. Guess the alphabet based on the give range.\n"; //number range is depend on the programmer
                    cout<< "\t2. You are allowed to make one guess at a time.\n";
                    cout<< "\t3. Each game has 5 chance to guess the corrent alphabet.\n"; // user is given 5 or more chance to guess the number
                    cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                    cout<< NEWLINE;
                    cout<< "\tGood Luck to You!";
                    cout<< NEWLINE;
                    cout<< "\tPlease guess from A to Z. 5 chances left. What is the alphabet?"; //use is ask to guess the number
                    cout<< NEWLINE;
                    
                   // break;
                   
                  // case 3:
                        cout<< "\tDIFFICULTY LEVEL\n";   // sub menu game
                        cout<< "\t===================\n";
                        cout<< "\tSelect a Difficulty Level" << endl;
                        cout<< "\tLevel 1: Easy (1-15)\n";    // range from 1 to 15
                        cout<< "\tLevel 2: Normal (1-20)\n";  // range from 1 to 20
                        cout<< "\tLevel 3: Hard (1-40)\n";     // range from 1 to 40
                        cout<< "\tTo return to Main Menu, type M\n";    // to return back to main menu 
                        cout<< NEWLINE;
                        
                        
                        
                        cout<< "\tSelect level to play\n";
                     /*   cin>>diffchoice;
                        
                        switch (diffchoice)
                        {
                               case '1': 
                                    maxrand = 15; chance = 5;
                                    break;
                                    
                                    case '2':
                                         maxrand = 20; chance = 4;
                                         break;
                                         
                                         case '3':
                                              maxrand = 40; chance = 3;
                                              break;
                                              
                                              default: exit(0);
                                              } */
                        //break;
                    
                    case 4:
                           cout<< "\tHigh Score\n";
                           cout<< "\t===========\n";
                           cout<< "\tGuess the Number Best Score: " /*<< <<*/ "chance use up" << endl;
                           cout<< "\tGuess the Alphabet Best Score: ";
                           cout<< NEWLINE;
                           system ("pause");
                           system ("cls");
                     
                           break;
                         
                         case 5:
                              system ("cls");
                              cout<< NEWLINE;
                              cout<< "\tCREDITED BY\n";
                              cout<< "\t================\n\n";
                              cout<< "\tName: Siti Radina A.Abdul Rahman\n"; // programmer name
                              cout<< "\tStudent ID: 00 - 300 908[ Y ]\n"; // programmer ID number
                              cout<< "\tCourse: BSc(Hons) in Information Technology 11/01\n"; // programmer Course study
                              cout<< "\tCountry: Brunei Darussalam\n"; // programmer home country
                              cout<< NEWLINE;
                              system ("pause");
                              system ("cls");
                              
                              break;
                           
                           case 6:
                                exit;
                                break;
                                
                                default:
                                        system("cls");
                                        cout<< NEWLINE;
                                        cout<< "\tWRONG INPUT!    Please Select 1 to 6 only";
                                        cout<< NEWLINE;
                                       // system("pause");
                                        
                                        break;
                                        }
                                        }

 return 0;   
}

still missing a feww coding here......

still missing a feww coding here......

So add the coding.

Since we didn't assign the task and you didn't bother asking a question, we don't know what you need, so we have nothing to say.

i'm still looking on it..... I'm not suppose to use arrays or pointers or vectors or any data structures in this coding...

Plus i'm still haven't been able to make a error capabilities or error free during runtime

// Randam Guessing Game 
#include <iostream>
#define NEWLINE "\n\n\n"
#include <cstdlib> // need to use rand() function
#include <ctime> // need to use time() function

using namespace std;

     
int main ()
{
    bool goOn = true;
    
    while (goOn)
    {
          
    srand((unsigned)time(0));
    
    int choice, result;
    
    
    
    while (choice != 6)
    {
    
   // cout<< "\tGuessing Game Program"; //Title of the Program
    cout<< NEWLINE;
    
    cout<< "\tMENU\n"; // Title
    cout<< "\t=====\n\n";
    cout<< "\t1. Guess the Number    [Range between 1 to 100.]\n"; 
    cout<< "\t2. Guess the Alpabet    [Range between A to Z.]\n";
    cout<< "\t3. Difficulty Level Game\n";
    cout<< "\t4. High Score [Current top score]\n"; // high score for both number and alphabet game
    cout<< "\t5. Credit\n"; // programmer detail
    cout<< "\t6. Quit    [Enter any key to exit program!]\n"; // Exit program
    cout<< NEWLINE;
    
    cout<< "\tSelect Menu ==> "; // user to input he or her choice of game
    cin>> choice;
    cout<< NEWLINE;
    
    switch (choice)
    {
           case 1:
                cout<< "\tGuess the Number\n"; // one of the selection choice that user has made
                cout<< "\t================\n\n";
                cout<< "\tInstructions:\n"; // list of instruction that user must follow
                cout<< "\t1. Guess the number based on the give range.\n"; //number range is depend on the programmer
                cout<< "\t2. You are allowed to make one guess at a time.\n";
                cout<< "\t3. Each game has 5 chance to guess the corrent number.\n"; // user is given 5 or more chance to guess the number
                cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                cout<< NEWLINE;
                cout<< "\tGood Luck to You!";
                cout<< NEWLINE;
                cout<< "\tPlease guess from 1 to 100. 5 chances left. What is the number?"; //use is ask to guess the number
                cout<< NEWLINE;
                
                break;
                
               // case 2:
                     
                    cout<< "\tGuess the Alphabet\n"; // one of the selection choice that use has made
                    cout<< "\t================\n\n";
                    cout<< "\tInstructions:\n"; // list of instruction that user must follow
                    cout<< "\t1. Guess the alphabet based on the give range.\n"; //number range is depend on the programmer
                    cout<< "\t2. You are allowed to make one guess at a time.\n";
                    cout<< "\t3. Each game has 5 chance to guess the corrent alphabet.\n"; // user is given 5 or more chance to guess the number
                    cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                    cout<< NEWLINE;
                    cout<< "\tGood Luck to You!";
                    cout<< NEWLINE;
                    cout<< "\tPlease guess from A to Z. 5 chances left. What is the alphabet?"; //use is ask to guess the number
                    cout<< NEWLINE;
                    
                   // break;
                   
                  // case 3:
                        cout<< "\tDIFFICULTY LEVEL\n";   // sub menu game
                        cout<< "\t===================\n";
                        cout<< "\tSelect a Difficulty Level" << endl;
                        cout<< "\tLevel 1: Easy (1-15)\n";    // range from 1 to 15
                        cout<< "\tLevel 2: Normal (1-20)\n";  // range from 1 to 20
                        cout<< "\tLevel 3: Hard (1-40)\n";     // range from 1 to 40
                        cout<< "\tTo return to Main Menu, type M\n";    // to return back to main menu 
                        cout<< NEWLINE;
                        
                        
                        
                        cout<< "\tSelect level to play\n";
                     /*   cin>>diffchoice;
                        
                        switch (diffchoice)
                        {
                               case '1': 
                                    maxrand = 15; chance = 5;
                                    break;
                                    
                                    case '2':
                                         maxrand = 20; chance = 4;
                                         break;
                                         
                                         case '3':
                                              maxrand = 40; chance = 3;
                                              break;
                                              
                                              default: exit(0);
                                              } */
                        //break;
                    
                    case 4:
                           system("cls");
                           cout<< NEWLINE;
                           cout<< "\tHigh Score\n";
                           cout<< "\t===========\n";
                           cout<< "\tGuess the Number Best Score: " /*<< <<*/ "chance use up" << endl;
                           cout<< "\tGuess the Alphabet Best Score: ";
                           cout<< NEWLINE;
                           system ("pause");
                           system ("cls");
                     
                           break;
                         
                         case 5:
                              system ("cls");
                              cout<< NEWLINE;
                              cout<< "\tCREDITED BY\n";
                              cout<< "\t================\n\n";
                              cout<< "\tName: Siti Radina A.Abdul Rahman\n"; // programmer name
                              cout<< "\tStudent ID: 00 - 300 908[ Y ]\n"; // programmer ID number
                              cout<< "\tCourse: BSc(Hons) in Information Technology 11/01\n"; // programmer Course study
                              cout<< "\tCountry: Brunei Darussalam\n"; // programmer home country
                              cout<< NEWLINE;
                              system ("pause");
                              system ("cls");
                              
                              break;
                           
                           case 6:
                                exit(0); // quit the game
                                break;
                                
                                default:
                                        system("cls");
                                        cout<< NEWLINE;
                                        cout<< "\tWRONG INPUT!    Please Select 1 to 6 only";
                                        cout<< NEWLINE;
                                       // system("pause");
                                        
                                        break;
                                        }
                                        }
                                        }

 return 0;   
}

so far i can get it back to the menu and have it exit and also the credit section.
i still can't get the score.

Do you want the high score to be recorded only while the program is running, or forever?

If you want it only while the program is running, you can create variables called "int highscoreNumber;" and "int highscoreAlphabet;" at the beginning of your int main(). Then, in your case 4, you can cout<< those values.

Of course, in your guessing game, you can assign actual values to the variables, based on how many guesses it took them.

If you want the highscore to be recorded forever, you should create a FILE called highscore.txt which contains the two values. You can access the file at the beginning of the program to retrieve the values. You can rewrite over the file if a new highscore is created.

Explain the problem in detail!!! Just posting code and expecting us to read your mind is not going to work well.

Do you want the high score to be recorded only while the program is running, or forever?

If you want it only while the program is running, you can create variables called "int highscoreNumber;" and "int highscoreAlphabet;" at the beginning of your int main(). Then, in your case 4, you can cout<< those values.

Of course, in your guessing game, you can assign actual values to the variables, based on how many guesses it took them.

If you want the highscore to be recorded forever, you should create a FILE called highscore.txt which contains the two values. You can access the file at the beginning of the program to retrieve the values. You can rewrite over the file if a new highscore is created.

Just to be recorded during the program is running only. Thanks for the hint..

Explain the problem in detail!!! Just posting code and expecting us to read your mind is not going to work well.

You don't have to take that tone with me...

here is the qns.


OBJECTIVE

• To test students’ capabilities of understanding on problem solving of how to write a complete and executable well-structured program by using only the three (3) control structures: sequence structure, selection structure and repetition structure.
• To design and implement appropriate functions to organize the codes modularly to ease maintenance and upgrades in the future

PROGRAM REQUIREMENTS

You are required to follow the requirements below; failure to do so may have impact on your marks:

• The program is to be written using structured programming method NOT object-oriented style.
• You ARE NOT allowed to use arrays, vectors, pointers or any data structures in this assignment.
• The number of lines of codes MUST BE NOT MORE THAN 800 lines.
• The program MUST HAVE at least 3 functions written by you other than main function.
• The guessing game MUST HAVE at least one menu to allow the player/user to choose the appropriate options. The number of options is up to the programmer to decide.
• Among the option of the guessing game, it MUST HAVE at least:
o A mini game of guessing a number from a range of random numbers. The range of numbers to be guessed should be made known to the player.
o A mini game of guessing an alphabet among the 26 alphabets.
o Score option to display the current score of any of the mini games played while the program is still in execution. The score of the guessing game SHALL NOT be stored onto any secondary storage unit (e.g. hard disk).
o Credit option to show your name, ID/Passport, course of study and country. It is compulsory to have this option in the program.
o Quit option to terminate the program. It is compulsory to have this option in the program.
• The number of times allowed to make correct guesses will be determined by you (the programmer), and it must be made known to the player that how many chances he/she has left to make a correct guess before revealing the answer.
• The guessing game must use the rand function from the cstdlib library file.

TIPS

1. Your program should use switch control structures and do/while control structures to properly construct the menus.
2. You should look at the ASCII table and use the idea to your advantage for the Guessing an alphabet mini game.
3. You should use the modulus operator to your advantage to scale the numbers appropriately.

BONUS COMPONENT

Your program may include the following features to extend the playability of the game. If you include any of the features correctly and appropriately, you will be awarded bonus marks (refer to the marking criteria on how to get the bonus marks). The following are the new features:

• The guessing a number mini game will have 3 difficulties: easy, normal and hard. You may include a sub-menu screen to allow user to choose:
o Easy difficulty
• 5 chances to guess
• Range of numbers is not more than 16 different numbers. E.g. Guess from 1 to 15.
o Normal difficulty
• 4 chances to guess
• Range of numbers is not more than 21 different numbers. E.g. Guess from 1 to 20
o Hard difficulty
• 3 chances to guess
• Range of numbers is not more than 41 different numbers. E.g. Guess from 1 to 40
o Return back to main menu

• The guessing an alphabet mini game will have 3 difficulties: easy, normal and hard. You may include a sub-menu screen to allow user to choose:
o Easy difficulty
• 2 chances to guess
• Guess vowel. E.g. a, e, i, o, u
o Normal difficulty
• 4 chances to guess
• Guess consonant. E.g. b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, z
o Hard difficulty
• 5 chances to guess
• Guess from all 26 alphabets
o Return back to main menu

So far this is the current coding i have.

// Randam Guessing Game 
#include <iostream>
#define NEWLINE "\n\n\n"
#include <cstdlib> // need to use rand() function
#include <ctime> // need to use time() function

using namespace std;

     
int main ()
{
    bool goOn = true;
    
    while (goOn)
    {
          srand(time(NULL));
          
          int choice, result, random, attempt = 1, guess;
          int highscoreNumber = 0, highscoreAlphabet = 0 , /*diffchoice, maxrand = 0, chance = 0*/;
          
          while (choice != 5)
          {
                cout<< NEWLINE;
                cout<< "\tMENU\n"; // Title
                cout<< "\t=====\n\n";
                cout<< "\t1. Guess the Number    [Range between 1 to 100.]\n"; 
                cout<< "\t2. Guess the Alpabet    [Range between A to Z.]\n";
                cout<< "\t3. High Score [Current top score]\n"; // high score for both number and alphabet game
                cout<< "\t4. Credit\n"; // programmer detail
                cout<< "\t5. Quit \n"; // Exit program
                cout<< NEWLINE;
                
                cout<< "\tSelect Menu ==> "; // user to input he or her choice of game
                cin>> choice;
                cout<< NEWLINE;
                
                
                switch (choice)
                {
                       case 1:
                       system("cls");
                            cout<< "\tGuess the Number\n"; // one of the selection choice that user has made
                            cout<< "\t================\n\n";
                            cout<< "\tInstructions:\n"; // list of instruction that user must follow
                            cout<< "\t1. Guess the number based on the give range.\n"; //number range is depend on the programmer
                            cout<< "\t2. You are allowed to make one guess at a time.\n";
                            cout<< "\t3. Each game has 5 chance to guess the corrent number.\n"; // user is given 5 or more chance to guess the number
                            cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                            cout<< NEWLINE;
                            cout<< "\tGood Luck to You!";
                            cout<< NEWLINE;
                            
                            
                            while (cin.good())
                            {
                            random = rand () % 100 + 1;
                            
                            
                            cout<< "\tPlease guess from 1 to 100. What is the number? "; //use is ask to guess the number
                            cin>> guess;
                
                            while(guess != random && cin.good())
                            {
                            attempt++;
                            
                            if(guess > random)
                            {
                                     cout<<endl<<"\t"<<guess<<" is too high";
                                     }
                                     else
                                     {
                                         cout<<endl<<"\t"<<guess<<" is too low";
                                         }
                                         cout<<"\n";
                                         cout<< "\tAttempt["<<attempt<<"] ";
                                         cin>> guess;
                                         }
            
                                         if (guess == random) {				
            			                 cout<<"\tCongratulations! You guessed the number in "<<attempt<<" tries"<<endl;
                                         cout<< NEWLINE;
                                         system("pause");
                                         system ("cls");
                                         break;
                
                case 2:
                    system ("cls") ;
                    cout<< "\tGuess the Alphabet\n"; // one of the selection choice that use has made
                    cout<< "\t================\n\n";
                    cout<< "\tInstructions:\n"; // list of instruction that user must follow
                    cout<< "\t1. Guess the alphabet based on the give range.\n"; //number range is depend on the programmer
                    cout<< "\t2. You are allowed to make one guess at a time.\n";
                    cout<< "\t3. Each game has 5 chance to guess the corrent alphabet.\n"; // user is given 5 or more chance to guess the number
                    cout<< "\t4. Once you have used up all your chancce, you lose the game!\n";
                    cout<< NEWLINE;
                    cout<< "\tGood Luck to You!";
                    cout<< NEWLINE;
                    cout<< "\tPlease guess from A to Z. 5 chances left. What is the alphabet?"; //use is ask to guess the number
                    cout<< NEWLINE;
                    
                    break;
                    
                    case 3:
                           system("cls");
                           cout<< NEWLINE;
                           cout<< "\tHigh Score\n";
                           cout<< "\t===========\n";
                           cout<< "\tGuess the Number Best Score: " << highscoreNumber << " attempt" << endl;
                           cout<< "\tGuess the Alphabet Best Score: "<< highscoreAlphabet << " attempt" << endl;
                           cout<< NEWLINE;
                           system ("pause");
                           system ("cls");
                     
                           break;
                         
                         case 4:
                              system ("cls");
                              cout<< NEWLINE;
                              cout<< "\tCREDITED BY\n";
                              cout<< "\t================\n\n";
                              cout<< "\tName: Siti Radina A.Abdul Rahman\n"; // programmer name
                              cout<< "\tStudent ID: 00 - 300 908[ Y ]\n"; // programmer ID number
                              cout<< "\tCourse: BSc(Hons) in Information Technology 11/01\n"; // programmer Course study
                              cout<< "\tCountry: Brunei Darussalam\n"; // programmer home country
                              cout<< NEWLINE;
                              system ("pause");
                              system ("cls");
                              
                              break;
                           
                           case 5:
                                exit(0); // quit the game
                                break;
                                
                                default:
                                        system("cls");
                                        cout<< NEWLINE;
                                        cout<< "\tWRONG INPUT!    Please Select 1 to 6 only";
                                        cout<< NEWLINE;
                                       // system("pause");
                                        
                                        break;
                                        }
                                        }
                                        }
                                        }
                                        }

 
}

I'm having problem of change the coding guessing number to Alphabet. and it will run till user enter the right number.

This is how you declare a variable and edit its value within a program:

#include <iostream.h>

int main() {
  int myAge = 22;
  cout << "My age is " << myAge << endl;
  myAge = 54;
  cout << "My age is " << myAge << endl;
return 0;
}

Line 4 is the declaration. After that, you use "myAge" without the "int".

// Randam Guessing Game 
#include <iostream>
#define NEWLINE "\n\n\n"
#include <cstdlib> // need to use rand() function
#include <ctime> // need to use time() function

using namespace std;

     
int main ()
{
    bool goOn = true;
    
    while (goOn)
    {
          srand(time(NULL));
          
          int choice, random, attempt = 1, guess;
          int highscoreNumber = 0, highscoreAlphabet = 0 ;
          char guess2;
          
          while (choice != 5)
          {
                cout<< NEWLINE;
                cout<< " MENU\n"; // Title
                cout<< " =====\n\n";
                cout<< " 1. Guess the Number    [Range between 1 to 100.]\n"; 
                cout<< " 2. Guess the Alpabet    [Range between A to Z.]\n";
                cout<< " 3. High Score [Current top score]\n"; // high score for both number and alphabet game
                cout<< " 4. Credit\n"; // programmer detail
                cout<< " 5. Quit \n"; // Exit program
                cout<< NEWLINE;
                
                cout<< " Select Menu ==> "; // user to input he or her choice of game
                cin>> choice;
                cout<< NEWLINE;
                
                
                switch (choice)
                {
                       case 1:
                            system("cls");
                            cout<< " Guess the Number\n"; // one of the selection choice that user has made
                            cout<< " ================\n\n";
                            cout<< " Instructions:\n"; // list of instruction that user must follow
                            cout<< " 1. Guess the number based on the give range.\n"; //number range is depend on the programmer
                            cout<< " 2. You are allowed to make one guess at a time.\n";
                            cout<< " 3. Each game lets the user guess the correct number .\n"; // lets the user to guess till it get the right number.
                            cout<< NEWLINE;
                            cout<< " Good Luck to You!";
                            cout<< NEWLINE;
                            
                            
                            while (cin.good())
                            {
                            random = rand () % 100 + 1;
                            
                            
                            cout<< " Please guess from 1 to 100. What is the number? "; //use is ask to guess the number
                            cin>> guess;
                            cout<< "\n";
                
                            while(guess != random && cin.good())
                            {
                            attempt++;
                            
                            if(guess > random)
                            {
                                     cout<< " " << guess <<" is too high" << endl;
                                     cout<< "\n";
                                     }
                                     else
                                     {
                                         cout<< " " << guess <<" is too low" << endl;
                                         cout<< "\n";
                                         }
                                         cout<<"\n";
                                         cout<< " Attempt["<<attempt<<"] ";
                                         cin>> guess;
                                         highscoreNumber++;
                                         }
                                         if (guess == random) 
                                         {
                                                   cout<<" Congratulations! You guessed the number in "<<attempt<<" tries"<<endl;
                                                   cout<< NEWLINE;
                                                   attempt = 1;
                                                   system("pause");
                                                   system ("cls");
                                                   break;
                                                   
                                                  /* case 2:
                                                        system ("cls") ;
                                                        cout<< " Guess the Alphabet\n"; // one of the selection choice that use has made
                                                        cout<< " ================\n\n";
                                                        cout<< " Instructions:\n"; // list of instruction that user must follow
                                                        cout<< " 1. Guess the alphabet based on the give range.\n"; //number range is depend on the programmer
                                                        cout<< " 2. You are allowed to make one guess at a time.\n";
                                                        cout<< " 3. Each game lets the user guess the correct alphabet.\n"; // lets the user to guess till it get the right alphabet.
                                                        cout<< NEWLINE;
                                                        cout<< " Good Luck to You!";
                                                        cout<< NEWLINE;
                                                       
                                                        while (cin.good())
                                                        {
                                                              random = rand ();
                                                        
                                                              cout<< " Please guess from A to Z. What is the alphabet?"; //use is ask to guess the alphabet
                                                              cin>> guess2;
                                                              cout<< "\n";
                                                              
                                                              while(guess2 != random && cin.good())
                                                              {
                                                                           attempt++;
                                                                           if(guess2 > random)
                                                                           {
                                                                                    cout<< " " << guess2 <<" Really close" << endl;
                                                                                    cout<< "\n";
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                         cout<< " " << guess2 <<" Still far" << endl;
                                                                                         cout<< "\n";
                                                                                         }
                                                                                         cout<<"\n";
                                                                                         cout<< " Attempt["<<attempt<<"] ";
                                                                                         cin>> guess2;
                                                                                         highscoreNumber++;
                                                                                         }
                                                                                         if (guess2 == random) 
                                                                                         {
                                                                                                   cout<<" Congratulations! You guessed the Alphabet in "<<attempt<<" tries"<<endl;
                                                                                                   cout<< NEWLINE;
                                                                                                   attempt = 1;
                                                                                                   system("pause");
                                                                                                   system ("cls");
                                                                                                   break; */
                                                      
                                                                                    case 3:
                                                                                         system("cls");
                                                                                         cout<< NEWLINE;
                                                                                         cout<< " High Score\n";
                                                                                         cout<< " ===========\n";
                                                                                         cout<< " Guess the Number Best Score: " << highscoreNumber << endl;
                                                                                         cout<< " Guess the Alphabet Best Score: "<< highscoreAlphabet  << endl;
                                                                                         cout<< NEWLINE;
                                                                                         system ("pause");
                                                                                         system ("cls");
                                                                                         break;
                                                                                       
                                                                                         case 4:
                                                                                              system ("cls");
                                                                                              cout<< NEWLINE;
                                                                                              cout<< " CREDITED BY\n";
                                                                                              cout<< " ================\n\n";
                                                                                              cout<< " Name: Siti Radina A.Abdul Rahman\n"; // programmer name
                                                                                              cout<< " Student ID: 00 - 300 908[ Y ]\n"; // programmer ID number
                                                                                              cout<< " Course: BSc(Hons) in Information Technology 11/01\n"; // programmer Course study
                                                                                              cout<< " Country: Brunei Darussalam\n"; // programmer home country
                                                                                              cout<< NEWLINE;
                                                                                              system ("pause");
                                                                                              system ("cls");
                                                                                              break;
                                                                                            
                                                                                              case 5:
                                                                                                   exit(0); // quit the game
                                                                                                   break;
                                                                                                 
                                                                                                   default:
                                                                                                           system("cls");
                                                                                                           cout<< NEWLINE;
                                                                                                           cout<< " WRONG INPUT!    Please Select 1 to 6 only";
                                                                                                           cout<< NEWLINE;
                                                                                                           break;
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                   //        }
                                                                                                 //          }
                            }

opinion on this coding...... should i change it?

I'm still having problem with the Alphabet part for the guessing game. but it will work. however i dont know how to put a limit to the attempt to guess. and that it will not go back to main menu.

// Randam Guessing Game
#include <iostream>
#define NEWLINE "\n\n\n"
#include <cstdlib> // need to use rand() function
#include <ctime> // need to use time() function

using namespace std;

    
int main ()
{
    bool goOn = true;
   
    while (goOn)
    {
          srand(time(NULL));
         
          int choice, random, attempt = 0, guess, random_char = rand();
          random_char+=85;
          int highscoreNumber = 0, highscoreAlphabet = 0 ;
          char guess2 = 0;
         
          while (choice != 5)
          {
                cout<< NEWLINE;
                cout<< " MENU\n"; // Title
                cout<< " =====\n\n";
                cout<< " 1. Guess the Number    [Range between 1 to 100.]\n";
                cout<< " 2. Guess the Alpabet    [Range between A to Z.]\n";
                cout<< " 3. High Score [Current top score]\n"; // high score for both number and alphabet game
                cout<< " 4. Credit\n"; // programmer detail
                cout<< " 5. Quit \n"; // Exit program
                cout<< NEWLINE;
               
                cout<< " Select Menu ==> "; // user to input he or her choice of game
                cin>> choice;
                cout<< NEWLINE;
               
               
                switch (choice)
                {
                   case 1:
                        system("cls");
                        cout<< " Guess the Number\n"; // one of the selection choice that user has made
                        cout<< " ================\n\n";
                        cout<< " Instructions:\n"; // list of instruction that user must follow
                        cout<< " 1. Guess the number based on the give range.\n"; //number range is depend on the programmer
                        cout<< " 2. You are allowed to make one guess at a time.\n";
                        cout<< " 3. Each game lets the user guess the correct number .\n"; // lets the user to guess till it get the right number.
                        cout<< NEWLINE;
                        cout<< " Good Luck to You!";
                        cout<< NEWLINE;
                           
                           
                        while (cin.good())
                        {
                           random = rand () % 100 + 1;
                           
                           
                           cout<< " Please guess from 1 to 100. What is the number? "; //user is ask to guess the number
                           cin>> guess;
                           cout<< "\n";
               
                           while(guess != random && cin.good())
                            {
                            //attempt++;
                            attempt = attempt + 1;
                           
                            if(guess > random)
                            {
                                     cout<< " " << guess <<" is too high" << endl;
                                     cout<< "\n";
                                     }
                                     else
                                     {
                                         cout<< " " << guess <<" is too low" << endl;
                                         cout<< "\n";
                                         }
                                         cout<<"\n";
                                         cout<< " Attempt["<<attempt<<"] ";
                                         cin>> guess;
                                       //  highscoreNumber++;
                                         }
                                         if (guess == random)
                                         {
                                                   highscoreNumber = highscoreNumber + 2;
                                                   cout<<" Congratulations! You guessed the number in "<<attempt<<" tries"<<endl;
                                                   cout<< NEWLINE;
                                                   attempt = 1;
                                                   system("pause");
                                                   system ("cls");
                                                   break;
                                                  
                                             /*  case 2:
                                                   system ("cls") ;
                                                   cout<< " Guess the Alphabet\n"; // one of the selection choice that use has made
                                                   cout<< " ================\n\n";
                                                   cout<< " Instructions:\n"; // list of instruction that user must follow
                                                   cout<< " 1. Guess the alphabet based on the give range.\n"; //alphabet range is depend on the programmer
                                                   cout<< " 2. You are allowed to make one guess at a time.\n";
                                                   cout<< " 3. Each game lets the user guess the correct alphabet.\n"; // lets the user to guess till it get the right alphabet.
                                                   cout<< NEWLINE;
                                                   cout<< " Good Luck to You!";
                                                   cout<< NEWLINE;
                                                      
                                                   while (cin.good())
                                                   {
                                                       random_char = 'a' + (rand ()% ('z' - 'a'));
                                                       
                                                             
                                                        cout<< " Please guess from A to Z. What is the alphabet? "; //user is ask to guess the alphabet
                                                        cin>> guess2;
                                                        cout<< "\n";
                                                             
                                                        while(guess2 != random_char && cin.good())
                                                        {
                                                                attempt++;
                                                                if(guess2 > random_char)
                                                                      {
                                                                             cout<< " " << guess2 <<" quite close" << endl;
                                                                             cout<< "\n";
                                                                             }
                                                                             else
                                                                                 {
                                                                                   cout<< " " << guess2 <<"  too far" << endl;
                                                                                   cout<< "\n";
                                                                                   }
                                                                                   cout<<"\n";
                                                                                   cout<< " Attempt["<<attempt<<"] ";
                                                                                   cin>> guess2;
                                                                                   //  highscoreAlphabe++;
                                                                                    }
                                                                                    if (guess2 == random)
                                                                                    {
                                                                                       cout<<" Congratulations! You guessed the Alphabet in "<<attempt<<" tries"<<endl;
                                                                                       cout<< NEWLINE;
                                                                                       attempt = 1;
                                                                                       system("pause");
                                                                                       system ("cls");
                                                                                       break; */
                                                     
                                                                                    case 3:
                                                                                         system("cls");
                                                                                         cout<< NEWLINE;
                                                                                         cout<< " High Score\n";
                                                                                         cout<< " ===========\n";
                                                                                         cout<< " Guess the Number Best Score: " << highscoreNumber << endl;
                                                                                         cout<< " Guess the Alphabet Best Score: "<< highscoreAlphabet  << endl;
                                                                                         cout<< NEWLINE;
                                                                                         system ("pause");
                                                                                         system ("cls");
                                                                                         break;
                                                                                      
                                                                                         case 4:
                                                                                              system ("cls");
                                                                                              cout<< NEWLINE;
                                                                                              cout<< " CREDITED BY\n";
                                                                                              cout<< " ================\n\n";
                                                                                              cout<< " Name: Siti Radina A.Abdul Rahman\n"; // programmer name
                                                                                              cout<< " Student ID: 00 - 300 908[ Y ]\n"; // programmer ID number
                                                                                              cout<< " Course: BSc(Hons) in Information Technology 11/01\n"; // programmer Course study
                                                                                              cout<< " Country: Brunei Darussalam\n"; // programmer home country
                                                                                              cout<< NEWLINE;
                                                                                              system ("pause");
                                                                                              system ("cls");
                                                                                              break;
                                                                                           
                                                                                              case 5:
                                                                                                   exit(0); // quit the game
                                                                                                   break;
                                                                                                
                                                                                                   default:
                                                                                                           system("cls");
                                                                                                           cout<< NEWLINE;
                                                                                                           cout<< " WRONG INPUT!    Please Select 1 to 6 only";
                                                                                                           cout<< NEWLINE;
                                                                                                           break;
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                           }
                                                                                                      //   }
                                                                                                    //    }
                            }

Dina A.Abdul Rahman
Email: [removed]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.