We were asked to write a program that will stimulate a high low game. User has 10 chances to get the random number between 1 and 100. Guessing it or not, the program will display the guesses the user entered. My output when I do guess the random number right is messed up. Any help will do good! Thank you again!
/*******************************************************************************
* Program Name:
* Author:
* Date:
* Course/Section: CSC-110
*Program Description:
*
*******************************************************************************/
/**************************** Compiler Directives *****************************/
#include <cstdlib>
#include <iostream>
#include <ctime>
usingnamespace std;
/************************** Global Data Declarations **************************/
//None in this program.
/**************************** Function Prototypes *****************************/
/*******************************************************************************
* Function Name: main
* Author: Chad Martinez
* Function Description:
*
* Pseudocode:
* Level 0
* ------- Variables
*
*******************************************************************************/
int main ()
{
//Local constants
constint SIZE = 10; //Sets the size of the array/chances
constint MIN = 1; //Change if lower range is needed
constint MAX = 100; //Change if higher range is needed
//Local variables
int count = 0; //Counter for array
int guess[SIZE]; //Array for having guesses stored into
int chances = 10; //Chances user has
char ans;
int tries = 0;
int count2 = 0;
int random; //Sets random number within range
/******************** Begin main Function Executables *************************/
do
{
//Creates Random number
srand(time(0));
random = (rand() % (MAX - MIN) + 1);
system("cls");
//Input guesses
do
{
cout << "I have a number between and including 1 and 100. You have " <<
chances << " to get it." << endl;
do
{
cout << "Guess #" << count + 1 << ": ";
cin >> guess[count];
tries++;
if ((guess[count] < MIN) || (guess[count] > MAX))
{
cout << "Please guess between " << MIN << " & " << MAX << " only."
<< endl;
}
elseif (guess[count] < random)
{
cout << guess[count] << " is low. Go higher." << endl;
}
elseif (guess[count] > random)
{
cout << guess[count] << " is high. Go lower." << endl;
}
elseif (guess[count] == random)
{
system("cls");
cout << "CONGRATULATIONS! " << random << " was the number"
<< " I had. It took you " << count + 1 << " try/ies." << endl
<< "Here are your guess/es:" << endl;
}
count++;
}while(guess[count] != random);
for (count2 = 0; count2 <= tries; count2 ++)
{
cout << "Guess #" << count2 + 1 <<": " << guess[count2]
<< endl;
}
//Successful Output
}while(tries != 10);
system("cls");
cout << "Sorry, you did not guess my number. It was " << random << "."
<< endl << "Here were your guesses:" << endl;
for (count = 0; count <= (tries - 1); count ++)
{
cout << "Guess #" << count + 1 << ": " << guess[count] << endl
<< endl;
}
//Unsuccessful Output
cout << "Try again? (Y/N): ";
cin >> ans;
}while (ans == 'Y' || ans == 'y');
//Calculations
//Clear the screen
//Display
//Hold execution on screen
system("pause");
//Indicate to OS successful termination of program
return 0;
//End main
}