Need help beginner C++ class (need by midnight!!!)

This is a discussion on Need help beginner C++ class (need by midnight!!!) within the C++ Programming forums, part of the General Programming Boards category; Hey everybody, I'm new here, but I missed today's class and was hoping to ask this while in class. This ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1
    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.
    Last edited by maestroanth; 03-21-2011 at 09:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Determining the Size of Class Objects tutorial question
    By Programmer_P in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2011, 09:11 PM
  2. Inheritance From Abstract Class Question(s)
    By Syndacate in forum C++ Programming
    Replies: 26
    Last Post: 02-13-2011, 02:58 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21