C++ cout setprecision() assign 10 temperatures

Description

C++ cout setprecision() assign 10 temperatures

#include <iostream>
using namespace std;
#include <iomanip.h>
const int NUM_TEMPS = 10;
void main()//from  w w w. ja va 2 s  .  co m
{
   float temps[NUM_TEMPS];
   int ctr;
   temps[0] = 178.6;       // Subscripts always begin at 0.
   temps[1] = 812.1;
   temps[2] = 719.5;
   temps[3] = 715.0;
   temps[4] = 715.4;
   temps[5] = 711.8;
   temps[6] = 173.3;
   temps[7] = 619.5;
   temps[8] = 174.1;
   temps[9] = 751.7;

   cout << "Daily temperatures for the last " << NUM_TEMPS << " days:\n";
   for (ctr=0; ctr<NUM_TEMPS; ctr++)
   {
      cout << setprecision(1) << temps[ctr] << "\n";
   }
   return;
}



PreviousNext

Related