include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

void printintromessage ();

void getUserInput (char& Y);

void printplayerinfo (const int& numofgamesinseries, const int& numofplayersonteam, int& i, int& j);

int main(int argc, char *argv[])
{
const int numofgamesinseries = 3;
const int numofplayersonteam = 4;
int i,j, score[numofgamesinseries][numofplayerson…
char Y = Y;

printintromessage ();

getUserInput (Y);
do
{
if (Y == 'Y' || Y == 'y')

{
printplayerinfo (numofgamesinseries, numofplayersonteam, i, j);
}

else
{
cout << "All finished ? Thank you !" << endl;
}
}

while ((Y == 'Y' || Y == 'y'));

system("PAUSE");
return EXIT_SUCCESS;
}

void printintromessage ()
{
cout << "This program processes bowling scores." << endl;
cout << "The user is asked to enter 3 bowling scores" << endl;
cout << "for each person on the team. There are 4 people" << endl;
cout << "per team. After all the scores are entered" << endl;
cout << "for a player, the program will list the individual" << endl;
cout << "game scores,the player's total score (series), and" << endl;
cout << "the player's average.After each team's input is complete," << endl;
cout << "the program will list the team's total scores by game," << endl;
cout << "the team's total score (series)and the team's average." << endl;
cout << "The user will then be asked if he/she wants to" << endl;
cout << "enter more data. If not, the program will list the" << endl;
cout << "team with the highest total score (series) and that " << endl;
cout << "total. If the user wants to enter more data," << endl;
cout << "the above process is repeated." << endl;
cout << " " << endl;
}

void getUserInput (char& Y)
{
cout << "Do you want to enter (more) data?" << endl;
cout << "Enter Y to continue, anything else to quit: ";
cin >> Y;
cout << " " << endl;
}

void printplayerinfo (const int& numofgamesinseries, const int& numofplayersonteam, int& i, int& j)
{
int score[numofgamesinseries][numofplayerson…

for (i = 1; i <= numofgamesinseries; i++)
{
for (j = 1; j <= numofplayersonteam; j++)
{
cout << "Enter player " << j << "'s score " << i << ": ";
cin >> score[i][j];
cout << score[i][j] << endl;

if (score[i][j] > 0 && score[i][j] <= 300)
{
cout << score[i][j] << endl;
}
else
{
cout << score[i][j] << " is not a valid score ! Score must be from 0 to 300" << endl;
cout << "Enter player " << j << "'s score " << i << ": ";
}
}
}
}

Ok so what is going on here is I am designing a program that stores bowling scores and then averages them up and displays the average and total score of all the players on a team. I set number of games per series (per player) to 3 and 4 players a team. I am attempting to use a multi array but it is not working what am I doing wrong. Also I am having an issues with verifying (such as the scores are only supposed to be between 0 and 300, and if the user inputs 400 it should say invalid input and reprompt them to enter a valid score.

So from the code I have posted what I am doing wrong, I am aware its not complete, but I need to get the score storing down first before moving on, please help I've been at this for many hours

Did you type this or copy/paste it? There are a couple things that I see that are blatantly wrong

const int numofgamesinseries = 3;
const int numofplayersonteam = 4;
int i,j, score[numofgamesinseries][numofplayerson… //<---what is this???

why the elipsis ('...')?

In addition, it is difficult to see what is going on because of your formatting, please read this article on formatting.

Are you getting compile errors or is it producing invalid results. "...it's not working... " isn't very descriptive.

Edited 6 Years Ago by Fbody: n/a

First , this is all my coding
second idk why the ellipse is there it is supposed to be a "]" and it a multiarray
third, it initializes, but outputs incorrectly, if you copy and paste it into dev C++ or whatever program you use you'll see what I am talking about, I've been at this for a day or two and I'm so frustrated >.<

I understand this is your code. I was asking if you typed into the code block directly or copy/pasted into the code block from your IDE...

If I copy/paste from here into my IDE (and correct the line I flagged) I get several compilation errors at lines 73 and 75. We can't replicate and analyze your error(s) unless you actually give us what you have.

From what I can tell, you are trying to use score[][] in a scope that it is not available in. Specifically, score is declared local to main() and you are trying to use the data contained in it locally to printplayerinfo(). This is not possible without passing it to the function.

Edited 6 Years Ago by Fbody: n/a

In addition to what Fbody said, you have an infinite loop.

char Y = 'Y'; //add 's around your char

printintromessage ();

getUserInput (Y);
do
{
if (Y == 'Y' || Y == 'y')

{
printplayerinfo (numofgamesinseries, numofplayersonteam, i, j);
//you'll have an infinite loop unless you stop it somehow
getUserInput (Y);
}

Also, I have better luck when I start for loops at zero:

for (i = 0; i < numofgamesinseries; i++)
{
for (j = 0; j < numofplayersonteam; j++)
{

score is declared local to main() and you are trying to use it locally to printplayerinfo(). This is not possible without passing it to the function.

True, but it has been redeclared within the function:

void printplayerinfo (const int& numofgamesinseries, const int& numofplayersonteam, int& i, int& j)
{
int score[numofgamesinseries][numofplayersonteam];

ok so I changed a few things up and im getting closer here is my new code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

void printintromessage ();

void getUserInput (char& Y);

void printplayerinfo (const int& numofgamesinseries, const int& numofplayersonteam, int& i);

int main(int argc, char *argv[])
{
    const int numofgamesinseries = 3;
    const int numofplayersonteam = 4;
    int i, score[numofgamesinseries];
    char Y = Y;
    
    printintromessage ();
    
    getUserInput (Y);
 do
 {   
    if (Y == 'Y' || Y == 'y')
    
         {
         printplayerinfo (numofgamesinseries, numofplayersonteam, i); 
         }
         
      else
         {
          cout << "All finished ? Thank you !" << endl;
         }  
         }    
 
 while ((Y == 'Y' || Y == 'y'));
 
    system("PAUSE");
    return EXIT_SUCCESS;
}

void printintromessage ()
     {
     cout << "This program processes bowling scores." << endl; 
     cout << "The user is asked to enter 3 bowling scores" << endl; 
     cout << "for each person on the team. There are 4 people" << endl;
     cout << "per team. After all the scores are entered" << endl;
     cout << "for a player, the program will list the individual" << endl;
     cout << "game scores,the player's total score (series), and" << endl;
     cout << "the player's average.After each team's input is complete," << endl;
     cout << "the program will list the team's total scores by game," << endl;
     cout << "the team's total score (series)and the team's average." << endl;
     cout << "The user will then be asked if he/she wants to" << endl;
     cout << "enter more data. If not, the program will list the" << endl;
     cout << "team with the highest total score (series) and that " << endl;
     cout << "total. If the user wants to enter more data," << endl;
     cout << "the above process is repeated." << endl;
     cout << " " << endl;
     }
     
void getUserInput (char& Y)
      {
      cout << "Do you want to enter (more) data?" << endl; 
      cout << "Enter Y to continue, anything else to quit: ";            
      cin >> Y;
      cout << " " << endl;
      }   
      
void printplayerinfo (const int& numofgamesinseries, const int& numofplayersonteam, int& i)
     {
        int score[numofgamesinseries];
        int j = 1;
                     
        for (i = 1; i <= numofgamesinseries; i++)              
        {
            for (j = 1; j <= numofplayersonteam; j++ )
            {
              cout << "Enter player " << j << "'s score " << i << ": ";
			  cin >> score[i];
         }        
        if (score [i] > 0 && score [i] <= 300)
         {
         cout << score[i] << endl;
         }
         else
         {
        cout << score[i] << " is not a valid score ! Score must be from 0 to 300" << endl;
         }
         }      
         }

Edited 6 Years Ago by MTW1989: fixed code

Why is your input part of your print function? I think you need to think about your program organization a little more...

The above is my code and this is what was assigned:

Write a program to process bowling scores for players on a team. Calculate each player's series (the sum of his bowling games) and his average game score. Sum the players' scores for each game, and calculate the team's total for each game, the team's series, and the team's average game score. For each player and each team, print the scores for each game, series, and average. Write the program so it can handle as many teams as the user wants to process or no teams at all. Allow the user to continue entering team scores until he indicates there are no more teams to process. If one or more teams' scores are entered, print the team number with the highest series and its series score at the end of the program. Name your source code file LetsGoBowling.cpp.

1.
Print an overview of the program's purpose. This should be in terms a user would understand. In the purpose, tell the user how many players are on each team and how many bowling scores there are per player. Make sure the purpose is printed only once per program execution.
2.
Ask the user if he/she wants to continue. He/she must be able to quit without having to enter a single team's score. As long as the user wants to continue entering data, prompt him/her for team's scores. There is no constant number of teams. The user must tell the program when he/she wants to quit.
3.
Process one team at a time. Prompt the user for the first team's scores by first asking for player one's score for game one, then game two, and then game three. Edit each bowling score, and do not continue the program until a valid value is entered. A bowling score can be between 0 and 300, inclusive. If an invalid score is entered, print an error message with the invalid score and request a valid score be entered. After player's one scores are correctly entered, calculate the series total by adding his/her games' scores. Calculate the player's game average (2 decimal precision) by dividing series by number of games. Then print that player's individual games' scores, his series, and his game average. Although three is generally recognized as the number of games in a bowling series, use a symbolic constant for number of games. For this program, assign the number three to the symbolic constant for number of games in a series. Code the program in a way that if the number of games ever changed in series, the only change to your program would be a change to the value of the symbolic constant.
4.
After the first player's processing is complete, start processing the other players' scores on the team. For this program's purpose, use a symbolic constant for the number of players on a team and assign it a value of four. Again, if number of players per team ever changes, the only change to your program should be the value of your symbolic constant.
5.
After all player's scores have been processed and printed, print the team totals for each game and series. Calculate the team's game average (2 decimal precision) by dividing the series total by the number of games in a series. Print team's game average.
6.
Ask the user if he wants to enter more data. Process each team as previously described if he/she does want to enter more data.
7.
When the user decides he/she doesn't want to continue, print the team number with the highest series and its series. For the purposes of this program, do not worry about teams tying for highest series. If two teams did have the same series, the honor of high series would remain with the first of the teams processed by the program. If the user quit the program before entering any teams, do not print any information on high series.
8.
Print a closing message to the user.
9.
Use an array to store the bowling scores. You may need more than one array. You do not need to use a two dimensional array but you can if you want. You must have at least 1 function that accepts an array as an argument and updates the array in the function. You may have more than one function that accepts an array as an argument. Do not use any global variables. Symbolic constants may be used and these may be global.

without needing the arrays id knock it out quick but the arrays are killing me.

This article has been dead for over six months. Start a new discussion instead.