I am attempting to make a number guessing game but I need to use functions I figured a good spot for this would be the greater and less than problems that I need to include to make the user know what they have, I am horrible with functions and dont know how i would write them, this is what i have for code (yes i got a most of it from asking other people on other websites)
#include<iostream>
#include<cstdlib>
#include<ctime>
#include <string> //added strings
using namespace std;
int main()
{
srand(time(0));
int guess;
char playAgain='y'; //new variable
while (playAgain !='n')
/*added a while loop so that the whole program
will loop while the new variable isn't 'n'*/
{
int number=rand()%1000+1;;
cout<<"Im thinking of a number between 1-1000. Take a guess: ";
cin>>guess;
while(guess!=number)
{
if(guess>number)
{
cout<<"Too high,Guess again: ";
cin>>guess;
}
else if(guess<number)
{
cout<<"Too low,Guess again: ";
cin>>guess;
}
}
if(guess=number)
{
cout<<"Congrats!! You got it.";
}
//do while loop so that the play again question loops for right answer
do {
cout << "Would you like to play again? y/n ";
cin >> playAgain;
} while (playAgain !='y' && playAgain !='n');
}
return 0;
}
I will be continuing to try and figure this out (the assignment is due in 24 hours ugh) hopefully someone will be able to help me