mustish1
asked on
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;
}
#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;
}
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?
ASKER
How to change this line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
scores[row][2] = (scores[row][0] + scores[row][1]) / 2.0;
scores[row][2] = (scores[row][0] + scores[row][1]) / 2.0;
NP. Glad to help : )