Simple question (I hope)

This is a discussion on Simple question (I hope) within the C++ Programming forums, part of the General Programming Boards category; I'm relatively new to C++ (my 3rd program). I developed a conversion table from Farenheit to Celsius (and vice versa). ...

  1. #1
    Newbie96
    Guest

    Simple question (I hope)

    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;
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    34
    One solution you may want to try is to nest the loops and print one line.
    Another is to read the data into an array then print each line of the array using your format

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    To make things easier, you could try just importing the whole std namespace instead of having all those using statements. This line of code imports it all:
    Code:
    using namespace std;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 09:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21