I'm trying to write a program for a guessing game where the user enters a number and tries to guess what number I have chosen. After the guess is entered the program should respond either your guess is too low, your guess is too high or congratulations you have guessed my number. I have to use the random generator to generate an integer. Here is the code I have written, but it's still not working right. I also have to check for invalid inputs. Can someone help me?
#include<iostream> // This is required to perform C+ stream I/O
#include<ctime> // This contains the prototype for the function time
#include<cstdlib> // Required for the exit function
#include<iomanip>
using namespace std;
int main()
{
// define variables
int numGuesses = 0; // This is a counter for the number of guesses
double myNumber = 77; // This will be the number I want the user to guess
char guess = ' '; // This is the number the user is guessing
double numReturned = guess; // This is the call random generator and gets a value between 1 and 100
int count = 0; // This is the counter for the number of guesses
double num = rand(); // This is for a number
char Play = 'y'; // 'n'entered will stop the program
cout << "\nWelcome, can you guess what number I am thinking of? ";
cout << "\nIt's a whole number between 1 to 100. How many guesses will you need: ";
cin >> numGuesses;
cout << "\nLet's begin! Enter your guess: ";
cin >> guess;
{
while ((myNumber > guess) && (myNumber != guess ))
{ count++; }
cout << "\nYour number is too low!" << endl;
if ( myNumber > guess && myNumber != guess )
{ count++; }
cout << "\nYour number is to high!" << endl;
The code needs code tags, and it also needs indentation, and you need to describe what your errors are.
What constitutes an invalid input? (Besides the y/n bit, anything else that would be invalid?)