Public Group

# Need Program to pause

This topic is 5069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

put

system("pause");

before

return 0;

##### Share on other sites
Man I'm good with these little mistakes...glad there's always someone around here to help. Thanks.

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites

tempcel = convert(tempfer);

after

cin >> tempfer;

##### Share on other sites
Thanks, now what did you mean by initialize the variables...?

##### Share on other sites
Like this:

float tempfer = 0.0;
float tempcel = 0.0;

##### Share on other sites
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
#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.

##### Share on other sites
Quote:
 Original post by alien3456I can't seem to find anything on "float convert(float)" so, what is that?
At 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.

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

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 12
• 17
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633359
• Total Posts
3011512
• ### Who's Online (See full list)

There are no registered users currently online

×