'calculation returns large negative number
Everything is working as it should, but every time I try to calculate the sales total for the number of seats sold in coach, I get a large negative number.
I think I'm missing a declaration for an initial value somewhere, but any changes I make don't seem to help. I feel like the issues is hiding out in my void totalSales, but I could be wrong. Any advice?
void totalSales(char seats[15][6], double seatRates[15])
{
double sales = 0;
int row, i, j;
for (i = 0; i < 15; i++)
{
row = 0;
for (j = 0; j < 6; j++)
{
if (seats[i][j] == '*')
{
row++;
}
}
sales += row * seatRates[i];
}
cout << "\n\nTotal Sales : $" << sales << "\n";
}
EDIT:
void seatingChart(char seats[15][6])
{
int i;
cout << "\n\nSeating Chart:\n";
cout << "\n First Class\n";
cout << "\n \t1 2\t3 4\n";
for (i = 0; i < 5; i++)
{
cout << "Row " << i + 1 << ":\t";
cout << seats[i][0] << " " << seats[i][1] << "\t";
cout << seats[i][2] << " " << seats[i][3] << "\n";
}
cout << "\n Coach\n";
cout << "\n\t1 2 3\t4 5 6\n";
for (i = 5; i < 15; i++)
{
cout << "Row " << i + 1 << ":\t";
cout << seats[i][0] << " " << seats[i][1] << " " << seats[i][2] << "\t";
cout << seats[i][3] << " " << seats[i][4] << " " << seats[i][5] << "\n";
}
}
void reserveSeat(char seats[15][6])
{
int row = 0, seat = 0;
while (seat == 0 && row == 0)
{
cout << "\n\nSelect a Seat\n";
cout << "First Class (1 - 5), Coach (6 - 15)\n";
cout << "Row: ";
cin >> row;
if (row <= 5)
{
cout << "Seat (1 - 4): ";
}
else
{
cout << "Seat (1 - 6) : ";
}
cin >> seat;
if (row < 1 || row > 15 || seat < 1 || seat > 6 || seats[row - 1][seat - 1] == '@')
{
cout << "Invalid Selection.\n";
seat = 0; row = 0;
}
else if (seats[row - 1][seat - 1] == '*')
{
cout << "Selected Seat Unavailable. Please choose another seat.\n";
seat = 0; row = 0;
}
else
{
seats[row - 1][seat - 1] = '*';
}
}
}
void totalSales(char seats[15][6], double seatRates[15]) // There is something wrong with my sales calculations.
{
double sales = 0;
int row, i, j;
for (i = 0; i < 15; i++)
{
row = 0;
for (j = 0; j < 6; j++)
{
if (seats[i][j] == '*')
{
row++;
}
}
sales += row * seatRates[i];
}
cout << "\n\nTotal Sales : $" << sales << "\n";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
