Temperature Converter

Platform:  C++
Published  Sep 30, 2008
Updated  Nov 15, 2008
I began learning C++ today, and this is my first snippet. It's a temperature converter.

Then you type in the temp and it gives you the conversion.

Screen:



Enjoy // Temperature Converter
// Coded by MountainDew

#include <iostream>
using namespace std;

int main ()
{
int temp,fahrenheit,celsius;
cout << "What is the temperature? ";
cin >> temp;
fahrenheit = temp * 9 / 5 + 32;
celsius = (temp - 32) * 5 / 9;
cout << temp << " F = " << celsius << " C" << endl;
cout << temp << " C = " << fahrenheit << " F" << endl << endl;
system("pause");
}

Comments

Sign in to comment.
nbjokhio   -  Dec 15, 2010
Great job..!! but your program is little bit confusing about writing lines, and can you please update, just like first it asks about which conversion; C-F, F-C, C-K, K-C..!! then converts it..!! thnkxx, looking forward for your assistance..!!
 Respond  
ChunkieMonkey   -  Nov 04, 2008
(late) But great job for what you say is your first...Keep it up!
 Respond  
jonesy44   -  Oct 05, 2008
awesome! Thanks md. looks cool, i've never thought about doing this kinda thing. i have a neat lil script for you sometime for your ipod :D:D
 Respond  
mountaindew   -  Oct 05, 2008
Check out this tut jonesy: http://www.cplusplus.com/doc/tutorial/

Download Visual C++ (is what I use) or Dev-C++

This is pretty much what this snippet is all about: http://www.cplusplus.com/doc/tutorial/basic_io.html
 Respond  
jonesy44   -  Oct 05, 2008
MD! i didn't know you did this stuff. yall have to teach me sometime :P
 Respond  
Roxas   -  Oct 05, 2008
I like it. Nice job for a first C++ snippet.
 Respond  
mountaindew   -  Oct 01, 2008
Updated, now you just input a number and it gives both conversions.
 Respond  
KronicDreamer   -  Oct 01, 2008
in c/c++ this is in every book and every tutorials when beginning and like napalm said... MUCH shorter :/
 Respond  
Hawkee   -  Oct 01, 2008
Yeah, napalm has a point. You could also do it like Google "30 C to F" or "100 F to C".
 Respond  
napalm`   -  Sep 30, 2008
Wish I still had visual installed, this could be done much easier.

'cin' a number then just display it converted to Fahrenheit and Celsius. This will shorten the code drastically.
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.