Need Program to pause
I need this program to pause, after is displays the celcius temperature.
Code:
/*A Jeremiah Cooper Production*/
#include <cstdlib>
#include <iostream>
using namespace std;
float convert(float);
int main()
{
float tempfer;
float tempcel;
cout << "Please enter the temperature in Fahrenheit: ";
cin >> tempfer;
cout << "\nHere's the temperature in Celcius: ";
cout << tempcel << endl;
return 0;
system("PAUSE");
}
float convert (float tempfer)
{
float tempcel;
tempcel = ((tempfer - 32) * 5) / 9;
return tempcel;
}
Man I'm good with these little mistakes...glad there's always someone around here to help. Thanks.
Since the problem was already solved, I think I'd like to point 1 thing...
Initalize the variables. IIRC it's bad practice to not do this.
Initalize the variables. IIRC it's bad practice to not do this.
Ok, well the program isnt working like it should. I put in 212 as the fahrenheit, which should be 100 celcius. And I get 6.12428e-39...whats the problem?
I was trying to tinker with the program and make it convert Celsius to Fahrenheit instead. I'm new so that's all I've been doing is tinkering. I ran into some trouble, and couldn't figure out a way to make it work.
Converting Fahrenheit to Celsius looks like this in his code:
tempcel = ((tempfer - 32) * 5) / 9;
And through my tinkering, my Celsius to Fahrenheit looks like this:
tempfer2 = ((tempcel2 * 9) / 5) + 32;
In my calculator (and in my head),
((212-32)*5)/9 = 100
and
((100*9)/5)+32 = 212
but in my program, they both work the same, making 212 into 100 on both equations.
Here is my code
I can't seem to find anything on "float convert(float)" so, what is that? I'd like to read up on it in my book if you could name what it is.
Converting Fahrenheit to Celsius looks like this in his code:
tempcel = ((tempfer - 32) * 5) / 9;
And through my tinkering, my Celsius to Fahrenheit looks like this:
tempfer2 = ((tempcel2 * 9) / 5) + 32;
In my calculator (and in my head),
((212-32)*5)/9 = 100
and
((100*9)/5)+32 = 212
but in my program, they both work the same, making 212 into 100 on both equations.
Here is my code
#include <cstdlib>#include <iostream>using namespace std;float convert(float);float convert2(float);int main(){float tempfer = 0.0;float tempcel = 0.0;float tempfer2 = 0.0;float tempcel2 = 0.0;cout << "Please enter a temperature in FAHRENHEIT: ";cin >> tempfer;tempcel = convert(tempfer);cout << "\nHere's the temperature in CELSIUS: ";cout << tempcel << endl;cout << "Please enter another temperature in CELSIUS: ";cin >> tempcel2;tempfer2 = convert(tempcel2);cout << "\nHere's the temperature in FAHRENHEIT: ";cout << tempfer2 << endl;system("PAUSE");return 0;}float convert (float tempfer){float tempcel;tempcel = ((tempfer - 32) * 5) / 9;return tempcel;}float convert2 (float tempcel2){float tempfer2;tempfer2 = ((tempcel2 * 9) / 5) + 32;return tempfer2;}
I can't seem to find anything on "float convert(float)" so, what is that? I'd like to read up on it in my book if you could name what it is.
Quote:Original post by alien3456At the top of the file he has float convert(float); as a function prototype or function declaration. At the bottom of the file, he has the full body for the function.
I can't seem to find anything on "float convert(float)" so, what is that?
By the way, it'd be nice to see some better naming and smarter variable use:
#include <iostream>float F2C(float F){ return (F - 32) * 5 / 9;}float C2F(float C){ return (C * 9 / 5) + 32;}int main(){ using namespace std; float F, C; cout << "Enter Fahrenheit temperature: "; cin >> F; cout << "Celcius temperature equivalent: " << F2C(F) << endl; cout << "Enter Celcius temperature: "; cin >> C; cout << "Fahrenheit temperature equivalent: " << C2F(C) << endl; // uncomment the following line if you're using a low-grade IDE :P // cin.get(); return 0;}
Next task: turn them into two command line utilities, F2C and C2F, which run like so:
C:\> F2C 212100CC:\> C2F 100212F
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement