Reputation: 29
How do I make this so that the numbers 1-10 print out next to the sales, instead of the sales under the 1-10?
void Bonus::calcAndDisplay(int salesArray[10][4], double rate)
{
for (int num = 1; num < 11; num += 1)
{
cout << num << "\n";
}
for (int row = 0; row < 10; row += 1)
{
for (int column = 0; column < 4; column += 1)
{
totSales += salesArray[row][column];
}
cout << totSales << "\n";
totSales = 0;
}
}
Upvotes: 0
Views: 2011
Reputation: 437
Fundamentally there is a structural problem with your code.
Once you have written to the console and moved on to the next line you cannot go back and write further on that line. (In general)
You need to re-consider your algorithm so that it writes the Number, sales and bonus in a single action rather than separating your loops into Loop1, loop2 then loop3.
I have taken the main for loop and moved your line that prints the COUNT inside the loop.
for (int row = 0; row < 10; row += 1)
{
cout << row << "\t";
for (int column = 0; column < 4; column += 1)
{
totSales += salesArray[row][column];
}
cout << totSales << "\n";
totSales = 0;
}
Note: \t is a tab feed... \t\t is two tab feeds.
I haven't tested the code but from here you should be able to make it work
Upvotes: 1