Help With Temperature Conersion chart

This is a discussion on Help With Temperature Conersion chart within the C++ Programming forums, part of the General Programming Boards category; So far I have gotten the temperature conversions from fahrenehit to celsius to print out properly. But when it comes ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    Help With Temperature Conersion chart

    So far I have gotten the temperature conversions from fahrenehit to celsius to print out properly. But when it comes to Celsius to Fahrenehit it prints out 65 constantly as well as 15.56 fahrenheit constantly. Our teacher mentioned something about Pass By Reference but im not sure were to use it. Any help is appreciated.
    Shawn
    Here is the CODE
    Code:
    #include <iostream>
    using namespace std;
    
    int main() 
    {	
    
       cout.precision(2); 
       cout.setf(ios::fixed); 
    
    const int LOWER = 0;
    const int UPPER = 60;
    const int STEP = 5;
    
    	int fahr = LOWER; 
    	double celsius = 0;
    	
    	/* Print table heading */
    	cout.width(19);
    	cout << "Fahrenheit";
    	cout.width(12);
    	cout << "Celsius";
    	cout.width(20);
    	cout << endl;
    
    	/* print table from LOWER to UPPER */
    	for (fahr = LOWER ; fahr <= UPPER ; fahr += STEP) 
                 {
    	cout.width(15);
    	cout << fahr;
    	celsius = (double(5)/9) * (fahr - 32);
    	cout.width(15);
    	cout << celsius;
    	cout.width(15);
    	cout <<endl;
                  }
    const int LOWER1 =0;
    const int UPPER1 =60;
    const int STEP1 =10;
    
       int cels = LOWER1;
       double fahrenheit = 0;
    
       cout.width(17);
       cout<<endl <<endl;
    	cout << "Celsius";
    	cout.width(15);
    	cout << "Fahrenheit";
    	cout.width(20);
    	cout << endl;
    
    for (cels = LOWER1; cels <= UPPER1 ; cels += STEP1)
    {
    	cout.width(15);
    	cout << fahr;
    	fahrenheit = (double(9)/5 * cels) + 32;
    	cout.width(15);
    	cout << celsius;
    	cout.width(15);
    	cout <<endl;
    }
    
    
    	return 0;
    }

  2. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Its because in your second loop you are using the variables from your first loop instead of the variables for the second loop. You are looping cels and updating fahrenheit, but printing celsius and fahr. You need a better system for variable names to keep stupid things like this from happening.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    Temperature Conversion

    Could some help me change the code that it stops printing out copies. Thanks for the help

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Copies of what? Doing what I said above would fix it from printing the same number over and over again if that is what you mean, otherwise I don't understand what you are asking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 02:15 PM
  2. Chart!
    By 98dodgeneondohc in forum C Programming
    Replies: 13
    Last Post: 04-22-2005, 11:03 AM
  3. Need help regarding ActiveX Chart Object
    By Hankyaku in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2005, 04:38 PM
  4. Help with temperature conversion Chart
    By sanmaximo in forum C++ Programming
    Replies: 1
    Last Post: 11-13-2003, 03:29 PM
  5. outputting a ASCII chart
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2002, 11:55 AM

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