I'm relatively new to C++ (my 3rd program). I developed a conversion table from Farenheit to Celsius (and vice versa). The program works. My question is, is there a way to get both tables to output side by side, so they appear on one screen.
Thanx for any input.
Here is my code
Code:#include <iostream> using std::cout; using std::endl; using std::ios; #include <iomanip> using std::setw; using std::setiosflags; using std::setprecision; double celsius( double ); // Function prototype void fahrenheit( double & ); //Function prototype int main() { cout << "Fahrenheit to Celsius Table\n\n"; //F to C table cout << setiosflags( ios::fixed | ios::showpoint ) << setprecision( 2 ); // sets calculated temp to 2 decimal points cout<<setw(3)<<"Farenheit"<<setw(18)<<"Celsius\n"<<setw(15); //F to C table header //loops in increments of 5 for values 32 to 212, produce output for ( int f = 32; f <= 212; f += 5) cout << setw(5) << f << setw(20) << celsius( f )<<setw(15)<<endl; // calls function cout << "\n\nCelsius to Fahrenheit Table\n\n"; //C to F table cout<<setw(3)<<"Celsius"<<setw(21)<<"Fahrenheit\n"<<setw(15); //C to F table header //loops in increments of 5 for values 0 to 100, produce output for ( int c = 0; c <= 100; c += 5 ){ double CelTemp = c; fahrenheit( CelTemp ); // calls function cout << setw(5) << c<< setw(20)<<CelTemp << setw(15)<<endl; } cout << endl; return 0; //indicates successful termination } //function definition, pass by value double celsius( double FarTemp ) { return (FarTemp - 32) * 5 / 9; } //function definition, pass by reference void fahrenheit( double &CelTemp ) { CelTemp = CelTemp * 9 / 5 + 32; }



LinkBack URL
About LinkBacks


