Jump to content

[C++ 09] Temperature Converter

- - - - -

  • Please log in to reply
1 reply to this topic

#1
CuzImAwesome

CuzImAwesome

    Newbie

  • Members
  • PipPip
  • 25 posts
Hey All! Heres a tutorial on how to make a simple console application that converts Celsius to Fahrenheit. I'm using Code::Blocks. :)

-----------------------------------------------------------------------------------------------------------------

So this is what it should look like at the start.
#include <iostream>
#include <cstdlib>
#include <cstdio>

int main(){
     using namespace std;




system("PAUSE");
return0;
}
Now we add the input for Celsius and the conversion factor.
#include <iostream>
#include <cstdlib>
#include <cstdio>

int main(){
     using namespace std;

     int celsius;
     cout << "Enter Temperature In Celsius: ";
     cin >> celsius;

     int conversion;
     conversion = 212 - 32;

system("PAUSE");
return0;
}
Now we add the conversion factor from celsius to fahrenheit.
#include <iostream>
#include <cstdlib>
#include <cstdio>

int main(){
     using namspace std;

     int celsius;
     cout << "Enter Temperature In Celsius: ";
     cin >> celsius;

     int conversion;
     conversion = 212 - 32;

     int fahrenheit;
     fahrenheit = conversion * celsius/100 + 32;

system("PAUSE");
return0;
}
Now we just output this on the screen.
#include <iostream>
#include <cstdlib>
#include <cstdio>

int main(){
     using namespace std;

     int celsius;
     cout << "Enter Temperature In Celsius: ";
     cin >> celsius;

     int conversion;
     conversion = 212 - 32;

     int fahrenheit;
     fahrenheit = conversion * celsius/100 + 32;

     cout << "The Temperature In Fahrenheit Is: ";
     cout << fahrenheit << endl;

system("PAUSE");
return0;
}
Hope this helped!!!!!! :)

Edited by Alexander, 03 November 2010 - 08:35 PM.
Corrected typos


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
A good tutorial, a few pointers though..
I had fixed some of your typographical errors (such as namspace), but you may wish to define your conversion factors and input as floats to allow decimal precision of the conversion, which is always useful.

Edited by Alexander, 03 November 2010 - 08:36 PM.

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users