C++ program help

Discussion in 'Software' started by Drunk3nP3ngu1n, Feb 3, 2008.

  1. Drunk3nP3ngu1n

    Drunk3nP3ngu1n Private E-2

    I'm trying to make a bowling program in C++. I have the basics down except for the math. If I bowl a spare or strike then 0's for the next few frames, the score keeps going up.

    Here is the code
    Code:
    /*
     * This program was made to calculate the score in a bowling game.
     * 
    */
    
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    int main()
    {
    	int throw_1, throw_2, throw_3, sum, count;
    	bool strike, spare;
    	count = 1;
    	sum = 0;
        throw_1 = 0;
        throw_2 = 0;  
    	do
    	{
    	cout << "Enter throw 1 of frame " << count << ": ";
    	cin >> throw_1;
    	if (throw_1 == 10)
    		{
    		cout << "Nice strike!" << endl;
    	    strike = true;
    		sum = sum + 10;
    		
    		}
    	else if (throw_1 <=10)
    		{
    		cout << "Enter throw 2 of frame " << count << ": ";
    		cin >> throw_2;
    			if (throw_1 + throw_2 == 10)
    			{
    			cout << "Nice spare!" << endl;
    			spare = true;
    			sum = sum + throw_1 + throw_2;
    			}     
    			else if (throw_1 + throw_2 > 10)
    			{
    				do
    				{
    				cout << "Enter throw 2 of frame " << count << ": ";
    				cin >> throw_2;
    				}
    				while (throw_1 + throw_2 > 10);
    			}
    			else
    			{
    			sum = sum + throw_1 + throw_2;
    			}
    		}
    	 else
    		{
    		cout << "Enter throw 2 of frame " << count << ": ";
    		cin >> throw_2;
    		if (throw_1 + throw_2 == 10)
    			{
    			cout << "Nice spare!" << endl;
    			}
    		sum = sum + throw_1 + throw_2;
    		}
        
        if(strike == true)
        {
         cout << sum << endl;
          sum = sum + 10 + throw_1;
        }
        
        else if(spare == true)
        {
        	cout << sum << endl;
          sum = sum + throw_1; //+ throw_2;
        }
                           
        
        if(sum == 300)
        {
          cout << "You bowled a perfect game!" << endl;
        } 
    	
        if (count >= 10)
    	{
    	cout << sum << endl;
    	}
    		++count;
    	}
    	while (count <= 10);
    	
    	
    system("PAUSE");
    }
    
    Here is a picture to illustrate what I am talking about.
    http://i27.tinypic.com/20kc9ya.jpg
     
  2. Wookie

    Wookie Sergeant Major

    try adding this to the beginning of the do, looks to me like once its set to true it never gets set back to false.

    strike = false;
    spare = false;
     
  3. Drunk3nP3ngu1n

    Drunk3nP3ngu1n Private E-2

    I finished the program. Can a mod please delete this thread.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds