10 Replies - 7228 Views - Last Post: 22 April 2012 - 12:06 PM Rate Topic: -----

#1 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

NEED HELP! Bowling Program

Posted 22 April 2012 - 11:19 AM

I need help with a Bowling Program I'm suppose to write. Here's what i have so far.

/*****************************************************************************
file Template_Project_5.cpp

     This program will analyze the scoring results for teams of bowlers who 
compete at a tournament. Each team of bowlers consists of five bowlers and 
each bowler bowls three games. You will be prompt to enter a bowler's score for
each of the three games they play. The program will then average their three
games together to get that bowlers average. The program will then add each
players average together and calculate the team's average for each team, three
teams in all. The program will then calculate which team wins the tournament 
through a nested if else statement The averages will then be sent to an external
file.
*******************************************************************************/


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>

using namespace std;

int main()
{

        int score,sum,bowler1_avg,bowler2_avg,bowler3_avg,
		bowler4_avg, bowler5_avg,team1_avg,team2_avg,team3_avg,
		win_avg; //this is the winning average for the tournament
	    ofstream outs;

cout<<"----------------------------Bowling Tourney---------------------------\n"
    <<"Welcome to the Bowling Tournament! You will be prompted to enter three\n"
    <<"scores per bowler. This program will then average those three scores\n"
    <<"entered to get the bowlers average. The bowlers average will be added\n"
    <<"to the team's total. The total will then be averaged. You will be\n"
    <<"prompted to do this three times, once per team. The program will then\n"
    <<"determine which team won the tournament.\n";


    //Describe program to user goes here

   
   outs.open("bowl.txt",ios::app);
    
    //Open external file and allow for appending to the file.  Add your code.
	

    //The following is pseudo-code that should help you set up the actual code
	for(int team = 1; team <= 3; team++)
	{
     outs<<team;
	 //Send team number to the external file
    
	//Initialize player averages for the team
       bowler1_avg=0;
       bowler2_avg=0;
       bowler3_avg=0;
       bowler4_avg=0;
       bowler5_avg=0;
       
       
	for (int bowler = 1; bowler <= 5; bowler++)   // 5 Loops for each player
	{
      sum=0;
 
	  for (int game = 1; game <= 3; game++)     // 3 Loops for each game
	  {
cout << "\nEnter score for bowler no. "<<bowler<<" on team no."<<team<<": ";
 cin >> score;
if (score <= -1 || score >= 301)
	       {
	      cout << "\nPlease enter a number between 0 and 300, both included.";
	       game--;
	       }
	        else
	       {
	       sum += score;
	            }
	        }
     cout << "\nAverage score for bowler no."<<bowler<<" on team"<<team<<"\n" 
          << " is " << sum / 3 << endl;
          
     outs << "\nAverage score for bowler no."<<bowler<<" on team"<<team<<"\n" 
          << " is " << sum / 3 << endl;
        
     


	    //Enter the score for the bowler from the keyboard and add it to
	    //the sum of scores for this bowler so far.
        
	   }//end for each game
      
	   switch(sum)
	   {
         case 1:cout<<bowler1_avg;
                break;
         case 2:cout<<bowler2_avg;
                break;
         case 3:cout<<bowler3_avg;
                break;
         case 4:cout<<bowler4_avg;
                break;
         case 5:cout<<bowler5_avg;
                break;
     
       
         
       }	
	   //Use a switch statement to select the particular bowler, compute the
	   //the average score for this bowler, and send it to the external file.
       
	  
	   }//end for each bowler
       team1_avg=0;
       team2_avg=0;
       team3_avg=0;
       
        
       team1_avg==bowler1_avg+bowler2_avg+bowler3_avg+bowler4_avg+bowler5_avg/5;
	   team2_avg==bowler1_avg+bowler2_avg+bowler3_avg+bowler4_avg+bowler5_avg/5;
	   team3_avg==bowler1_avg+bowler2_avg+bowler3_avg+bowler4_avg+bowler5_avg/5;
	   
       cout<<"Team 1 average score is "<<team1_avg<<"\n"
           <<"Team 2 average score is "<<team2_avg<<"\n"
           <<"Team 3 average score is "<<team3_avg<<"\n";
       outs<<team1_avg,team2_avg,team3_avg;
	   
	   
	   switch(team1_avg)
	   {
         case 1:team1_avg;
                  break;
         case 2:team2_avg;
                  break;
         case 3:team3_avg;
                  break;
       }
	  //Compute team average for each team and send team average
	  //to external file.  Use a switch statement to select the
	  //particular team for whcih the team average is being computed.
	  //Make sure each team average is properly rounded to an integer value.

	  
		
	//End for each team
	if(team1_avg>team2_avg&&team3_avg)
	{
	   team1_avg=win_avg;
       cout<<"Team 1 is the winner! They bowled"<<win_avg<<"as a team!\n";
    }
    else if(team2_avg>team1_avg&&team3_avg)
    {
       team2_avg=win_avg;
       cout<<"Team 2 is the winner! They bowled"<<win_avg<<"as a team!\n";
    }
    else if(team3_avg>team1_avg&&team2_avg)
    {   
       team3_avg=win_avg;
       cout<<"Team 3 is the winner! They bowled"<<win_avg<<"as a team!\n";
    } 
      
    
	//From the team average computed above, determine which team wins or
	//which tams tie in the tournament.  You'll need to apply nested if else
	//logic to do this.  Send the result to the external file.
	
	outs<<endl<<endl<<endl;
	outs.close();
    system("PAUSE");
	return 0;
}



I'm suppose to enter in 3 scores for 1 bowler, have those scores average, then add the avg to the score for that bowlers team. There are three teams. Then, I need to determine the average for each team. I can easily get the averages for the bowlers, but idk how to extract them from the for loop. Each time it goes through the loop, the variable bowler changes, meaning i cannot intialize the bowler average.

Is This A Good Question/Topic? 0
  • +

Replies To: NEED HELP! Bowling Program

#2 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,112
  • Joined: 25-December 09

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:30 AM

You should probably consider using vectors or arrays to hold the information so you can use it later.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:35 AM

I was told specifically not to use arrays and i don't think our class has gone over vectors.

The averages compute just fine, but I have no way of accessing them after they have been computed(at least idk how to). Once they are computer, I have no way of adding the averages together to determine the team average.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,112
  • Joined: 25-December 09

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:37 AM

If you can't use arrays then vectors are probably not an option. However you may want to start by addressing the following warning messages:

Quote

main.cpp||In function ‘int main()’:|
main.cpp|94|warning: switch missing default case [-Wswitch-default]|
main.cpp|120|warning: statement has no effect [-Wunused-value]|
main.cpp|121|warning: statement has no effect [-Wunused-value]|
main.cpp|122|warning: statement has no effect [-Wunused-value]|
main.cpp|127|warning: right operand of comma operator has no effect [-Wunused-value]|
main.cpp|127|warning: right operand of comma operator has no effect [-Wunused-value]|
main.cpp|132|warning: statement has no effect [-Wunused-value]|
main.cpp|134|warning: statement has no effect [-Wunused-value]|
main.cpp|136|warning: statement has no effect [-Wunused-value]|
main.cpp|130|warning: switch missing default case [-Wswitch-default]|
main.cpp|149|warning: ‘win_avg’ may be used uninitialized in this function [-Wuninitialized]|
||=== Build finished: 0 errors, 11 warnings ===|


Jim
Was This Post Helpful? 0
  • +
  • -

#5 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:39 AM

that's the problem, idk how to address those warnings. All i know is that I can find the average for each bowler, but I cannot find the averages for the team nor can I determine who won the tournament. I even asked the teacher for help, yet I received none.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,112
  • Joined: 25-December 09

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:52 AM

Do you know how to read those error messages? They tell you where to start looking. The first is telling you that you should have a default case in your switch statement. This is recommended to insure that if you forget a case the default case will catch this error. It is not absolutely necessary but you is a good practice.

The second error message:

Quote

main.cpp|120|warning: statement has no effect [-Wunused-value]|

Refers to line 120 and line 120 is:
 team1_avg==bowler1_avg+bowler2_avg+bowler3_avg+bowler4_avg+bowler5_avg/5;

Here you are using a comparison operator== when you probably meant to use the assignment operator=.

Now try to figure out the rest of the problems. Th number in the warning is the line number where the compiler detected the error.

Jim
Was This Post Helpful? 0
  • +
  • -

#7 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:55 AM

the program computer fine. I can enter in the averages, they do average out, but then I have no way of adding these averages to a team average variable. I also must use the switch statement somehow to computer the players average, which idk how to do.

*computes
Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,112
  • Joined: 25-December 09

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:55 AM

The warning messages I posted are part of your problem. You need to fix them. What compiler are you using?

Jim
Was This Post Helpful? 0
  • +
  • -

#9 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 11:57 AM

Bloodshed
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg   User is offline

  • member icon

Reputation: 5521
  • View blog
  • Posts: 17,112
  • Joined: 25-December 09

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 12:03 PM

You either need to figure out how to change the compiler settings or find a more up to date compiler/IDE to compile your programs. The compiler you are using is very old, has many bugs, and is no longer maintained.

Most of your problems will go away if you fix the warnings I provided.

Jim
Was This Post Helpful? 0
  • +
  • -

#11 Duckster18   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-April 12

Re: NEED HELP! Bowling Program

Posted 22 April 2012 - 12:06 PM

sadly,I can't. This is the compiler we were given for the class. We must use Bloodshed. Idk how to change the settings. I am very new to C++. I can compile and run the program that I have right now, I just need to find a means of adding the values I enter together to get the int value bowler1_avg, bowler2_avg,etc. If i get those, I can then add them together so I can get team1_avg,team2_avg, etc.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1