C++ float type Averages six test scores.

Description

C++ float type Averages six test scores.

#include <iostream>
using namespace std;
#include <iomanip.h>
void main()//  w  ww  .  ja v  a2s . c  o  m
{
   char s_name[] = "University";
   float scores[6] = {8.7, 9.4, 6.0, 7.0, 10.0, 6.7};
   float average=0.0;
   int ctr;

   for (ctr=0; ctr<6; ctr++)
   {
      average += scores[ctr];
   }

   average /= float(6);
   cout << "At " 
        << s_name 
        << ", your class average is " 
        << setprecision(2) << average << "\n";
   return;
}



PreviousNext

Related