1. ## for loops

I'm having trouble incorporating this for loop:

Code:
```	double sum;
for (int row= 0; row < i; row ++)
{
cout << Names[row] << "    ";
int col=0;
for (col= 0; col < num; col ++)
cout << Scores[row][col] << "   ";
cout << "\n";
}```
Into this one:

Code:
```cout << fixed << showpoint << setprecision (2);
for (int row =0; row < i; row++) //For each student, calculate the average score. Average for each row.
{
sum= 0;
for (int col =0; col < num; col++)
sum= sum + Scores[row][col];

AvgStudentScore[row]= (float) sum/num;

if (AvgStudentScore [row] > 90)

else if (AvgStudentScore [row] > 80)

else if (AvgStudentScore [row] > 67.5)

else if (AvgStudentScore [row] > 55)

else

cout << "* " << AvgStudentScore[row] << "   " << Grade[row] << "\n";
}```
I tried this:
Code:
```double sum;
cout << fixed << showpoint << setprecision (2);
for (int row= 0; row < i; row ++)
{
cout << Names[row] << "    ";
sum=0;
int col=0;
for (col= 0; col < num; col ++)
cout << Scores[row][col] << "   ";
sum= sum + Scores[row][col];
cout << "\n";
AvgStudentScore[row]= (float) sum/num;

if (AvgStudentScore [row] > 90)

else if (AvgStudentScore [row] > 80)

else if (AvgStudentScore [row] > 67.5)

else if (AvgStudentScore [row] > 55)

else

cout << "* " << AvgStudentScore[row] << "   " << Grade[row] << "\n";
}```
But the final code does not give me the results I am looking for. The average given by the last code is very very strange. Note, that when I have both for loops (first two loops) I do get the correct results (average), however, the results do not show up where they are supposed to be, which is, next to other data that I have in my program.

Any ideas anyone? 2. How in the world do you cut and paste and lose your braces? Edit: I guess you didn't lose your braces so much as delete one of your for loops (note originally you had four, now you have two, and you merged one -- the row one -- fine). 3. Are you saying I still need to use all for loops even after merging? 4. Consider the line
Code:
`sum= sum + Scores[row][col];`
Before: in a for loop. After: not in a for loop. There's nothing wrong with merging (in fact I would recommend that you do so), but you can't change things. 5. Great! Thanks for pointing that out. I was in fact missing the sum formula inside the for loop and needed curly braces for that as well. Popular pages Recent additions 