Hey everybody, I'm new here, but I missed today's class and was hoping to ask this while in class. This is what I have so far, basically part 4 of this program is to add instead of the user guessing a random number from 1-10 (with a point system and multiple games played), we're suppose to add an option where the user gets to input what number range he actually wants before the games start. (Like for example, you want a guessing game from 42 to 9000)
I'm confused about the random number function on how to do this, and was just going off what she original gave is which is numberToGuess = rand() % (10 - 1 +1 ) + 1; at the beginning of this project. I figure 10 is the range, and +1 isn't to make it zero (I don't know which +1), so what am I suppose to modify?
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(unsigned int(time(NULL)));
int numberToGuess; //number the computer makes
int guess; //the number the user inputs
int points; //to keep track of points
int totalPoints = 0; //keeps track of cumulative points
double totalGames = 0; //keeps track of number games and makes output a real number
int highNumber; //the high number user inputs for range
int lowNumber; //the low number user inputs in range
char quit; //to prompt quit command as a letter
int range;
cout<<"What do you want to be the lowest number?"<<endl;
cin>>lowNumber;
cout<<"What do you want to be the highest number?"<<endl;
cin>>highNumber;
do //loops for desired multiple games
{
points = 5;
numberToGuess = rand() % (10 - 1 +1 ) + 1;
cout<<"Input number"<<endl;
cin>>guess;
while (numberToGuess != guess) //loop until they guess right
{
if (guess > numberToGuess)
{
cout<<"too high" <<endl;
}
else
{
cout<<"too low" << endl;
}
points--;
cout<<"Input number"<<endl;
cin>>guess;
}
cout<<"correct"<<endl;
if (points < 0) //points don't get outputted as a negative number
{
points = 0;
}
totalPoints = totalPoints + points;
totalGames++;
cout<<points<<" points you have remaining."<<endl;
cout<<" Do you wish to stop playing y/n?";
cin>>quit;
tolower(quit);
} while (quit == 'n');
//final outputs
cout<<"Your total points are "<<totalPoints<<"."<<endl;
cout<<"The number of games you played are "<<totalGames<<"."<<endl;
cout<<"The average number of points you earn per game are "<<(totalPoints/totalGames)<<"."<<endl;
system("pause");
return 0;
}
//No Problems. Tests run perfectly!
Modify the program so that the user can set up a range to start the program it will not always be 1 to 10. All games once started will have the same range. Make sure the range is valid. (are the exact directions, originally the numbers were always 1 -10 with a point system.
Modify the program so that the user can set up a range to start the program it will not always be 1 to 10. All games once started will have the same range. Make sure the range is valid. (are the exact directions, originally the numbers were always 1 -10 with a point system.
nvm...got it.