'(C++) I am trying to output the contents in a double array but it's not printing any decimal places when I need them to have a .00 on the end

[This is my first semester learning C++ so bear with me :) please]

I was able to write the program to work as intended, but without the decimal places that my professor wants in step 3 (seen below)

  1. Declare three arrays of double type and initialize them with the following values:

mathScores[] {93, 88, 93, 84, 90}

chemScores[] {77, 92, 84, 76, 82}

avgScores[] {0, 0, 0, 0, 0}

  1. Compute the average scores using the for loop: avgScores[i] = (mathScores[i] + chemScores[i])/2
  2. Print the results on the screen nicely as shown below:

ID math chem average

0 93.00 77.00 85.00

1 88.00 92.00 90.00

. . .

Any ideas to get the decimals to output when I click run because whenever I run the program it just outputs 93, 77, 85, etc. instead of 93.00, 77.00, 85.00, etc. like my professor wants. Also, the setw() is to ensure the outputted values are spaced apart. (code I wrote is seen below)

double mathScores[] = {93, 88, 93, 84, 90};
double chemScores[] = {77, 92, 84, 76, 82};
double avgScores[] = {0, 0, 0, 0, 0};

cout << "ID" << setw(5) << "Math" << setw(5) << " Chem " << setw(5) << "Average" << endl;

for (int i=0; i<=4; i++) {
    avgScores[i] = (mathScores[i] + chemScores[i])/2;
    cout << i << setw(5) << mathScores[i] << setw(5) << chemScores[i] << setw(6) << avgScores[i] << endl;
    cout << endl;
}
return 0;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source