Shows zero values

Hi guys: Can any one please tell me what i made mistake as it shows the output zero. Thanks.


#include <iostream>
#include <iomanip>
using namespace test;

int main()
{
      double scores[5][3] = {{75.5, 80.5, 0.0},
                                       {88.5, 89.5, 0.0},
                                        {63.0, 54.0, 0.0},
                                       {100.0, 99.0, 0.0},
                                       {88.5, 88.5, 0.0}};
 
      for (int row = 0; row < 5; row += 1)
            scores[row][0] = scores[row][0] + scores[row][1] / 2;

      cout << endl << fixed << setprecision(1);
      for (int row = 0; row < 5; row += 1)
            cout << "The " << row + 1 << " average: " 
                  << scores[row][2] << endl;

      system("pause");
    return 0;
}
mustish1Asked:
Who is Participating?
 
käµfm³d 👽Commented:
How to change this line
That depends on what it is you are trying to print. My guess is that you want to print the values you just added and stored. If so, you stored them in the first slot (index 0); change your print statement to point there:
cout << "The " << row + 1 << " average: "
                  << scores[row][0] << endl;

Open in new window

0
 
käµfm³d 👽Commented:
Your print statement is always printing the 3rd element (index 2) in each set, which you defaulted to 0.0 in each case. Is this what you intended?
0
 
mustish1Author Commented:
How to change this line
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ozoCommented:
Did you mean to print   scores[row][0] ?
Did you mean to set  scores[row][2] to something other than 0?
0
 
mustish1Author Commented:
Thanks.
scores[row][2] = (scores[row][0] + scores[row][1]) / 2.0;
0
 
käµfm³d 👽Commented:
NP. Glad to help  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.