Convert Celsius to Fahrenheit for a range of value using while loop - C++ Statement

C++ examples for Statement:while

Description

Convert Celsius to Fahrenheit for a range of value using while loop

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
int main()/*from   w ww .  j  av  a2s  .c o m*/
{
   const int MAX_CELSIUS = 50;
   const int START_VAL = 5;
   const int STEP_SIZE = 5;
   int celsius;
   double fahren;
   cout << "DEGREES   DEGREES\n" << "CELSIUS  FAHRENHEIT\n" << "-------  ----------\n";
   celsius = START_VAL;
   // Set output formats for floating-point numbers only
   cout << setiosflags(ios::showpoint) << setprecision(2);
   while (celsius <= MAX_CELSIUS)
   {
      fahren = (9.0/5.0) * celsius + 32.0;
      cout << setw(4)  << celsius << fixed << setw(13) << fahren << endl;
      celsius = celsius + STEP_SIZE;
   }
   return 0;
}

Result


Related Tutorials