//using MSVC++ 6.0
just change the "20" in the for loop to a "100".
the "20" is used in the for loop to show you how the "temperature in F" and "temperature in C" are arranged.
I hope the formulas are correct.
Code:
/*cheap method: do this by the use of tabs*/
#include<iostream.h>
double FtoC(double temp) // convert from F to C
{
return((temp-32.0)/1.8);
}
double CtoF(double temp) // convert from C to F
{
return((temp*1.8)+32.0);
}
int main(void)
{
int x=0;
cout<<"temperature in F"<<"\t"<<"temperature in C"<<endl;
for(x=0;x<=20;x++) //212_F=100_C
{
cout<<x<<"\t\t\t"<<double(FtoC(x))<<endl;
}
return 0;
}
Code:
/*using cout class*/
#include<iostream.h>
#include<iomanip.h>
double FtoC(double temp) // convert from F to C
{
return((temp-32.0)/1.8);
}
double CtoF(double temp) // convert from C to F
{
return((temp*1.8)+32.0);
}
int main(void)
{
int x;
cout<<"temperature in F"<<"\t"<<"temperature in C"<<endl;
for(x=0;x<=20;x++) //212_F=100_C
{
cout.width(16); // refer to comment one
cout<<x;
cout<<"\t";
cout.width(16); // refer to comment one
cout<<double(FtoC(x))<<endl;
}
return 0;
}
/* comment one:
the argument value in the cout class member function width() is set to 16 because both "temperature in F" and "temperature in C" are 16 characters long.
*/
have fun.
you can also add in argc and *argv to main for a specific temperature conversion.