Jump to content
  • Advertisement
Sign in to follow this  
Coop56

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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by alien3456
I 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 212
100C

C:\> C2F 100
212F

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!