This program converts Celsius degrees to Fahrenheit degrees and Kelvin.
When I run this code in Dev C++ I get Celsius values going from 2 to 300. How do I get the code to output Celsius values starting from -300 and ending at 300?
I clearly set cels = -300 in the for loop. So why does the output start from 2?
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double cels, fah, kel, cels2fah, cels2kel, fah2cels, fah2kel;
cout<<"My Name \n";
cout<<"Program 8.0 "<<endl;
cout<<"\n\n";
cout<<"Celsius Fahrenheit Kelvin \n"
<<"Degrees Degrees --------\n"
<<"-------- ----------- --------\n";
for(cels = -300; cels<= 300; cels++)
{
cels2fah = (cels*9.0/5)+32.0;
cels2kel = cels+273.15;
setprecision(4.0);
cout<<setw(3)<< cels <<" "
<<setw(12)<< cels2fah <<" "
<<setw(14)<< cels2kel <<" \n";
}
system("PAUSE");
return 0;
}
I think the output is scrolling as has too many lines to hold in the buffer on the screen (tried on VS 2010/XP). The final output has lines only from 2 onwards to 300.
Don’t worry, the output is printing but unforunately not seen in the final window on Windows at least.
Try logging the output to an output file instead.