In the array, it is very simple I need to write code that displays the total salary for each of the 3 teams whose player salaries are stored in the above array.
It is taking in that with no problem, but there is two things that it is doing wrong
1: it is displaying an average of the salary entered for the team
2: at the end it displays a long negative number like "Team Salaries: -572662206.7"
can you offer any insight.
here is my code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int numberOfteams = 3;
const int numberOfplayers = 4;
int player_salary[numberOfplayers][numberOfteams];
int team,
player,
salary;
double salary_sum,
team_sum;
Pay attention:
int player_salary[numberOfplayers][numberOfteams];
and when you use it
cin >> player_salary[team][salary];
That writes to a unknown position:
If the first index reffers to player and the second to teams you CAN NOT exchange them. This cause bad things:
you are writing in a position which is not allowed (player_salary[3][2] is somewhere but is out of boundaries).
Your code is confusing: why are you using the variable salary to cycle over players and (later) over teams?
Or better: why do you need it?
Your for cycle should always look like
1 2 3 4 5 6
for (player = 0; player<numberOfplayers;++player)
{
for (team = 0; team<numberOfteams;++player)
{//do something on player_salary[player][team]
}
}