Top

Temperature Converter


C++ Code
+ 1 likes
Please Register to submit score.
Bookmark and Share
Average Score  5.0 (of 2 scores)
Date Added  Sep 30, 2008
Last Updated  Nov 15, 2008
Tags  c  celsius  cf  converter  fahrenheit  fc  temperature 

Introduction

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

Grab the Code

// 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

  (9)  RSS
napalm`
Comments: 182
 
C++ Snippet:  Temperature Converter
Posted on Sep 30, 2008 7:32 pm
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.
Hawkee
Comments: 1,039
 
C++ Snippet:  Temperature Converter
Posted on Oct 1, 2008 7:10 am
Yeah, napalm has a point. You could also do it like Google "30 C to F" or "100 F to C".
KronicDreamer
Comments: 46
 
C++ Snippet:  Temperature Converter
Posted on Oct 1, 2008 7:21 am
in c/c++ this is in every book and every tutorials when beginning and like napalm said... MUCH shorter :/
mountaindew
Comments: 1,826
 
C++ Snippet:  Temperature Converter
Posted on Oct 1, 2008 2:09 pm
Updated, now you just input a number and it gives both conversions.
Roxas
Comments: 20
 
C++ Snippet:  Temperature Converter
Posted on Oct 5, 2008 6:01 am
I like it. Nice job for a first C++ snippet.
jonesy44
Comments: 1,856
 
C++ Snippet:  Temperature Converter
Posted on Oct 5, 2008 6:04 am
MD! i didn't know you did this stuff. yall have to teach me sometime :P
mountaindew
Comments: 1,826
 
C++ Snippet:  Temperature Converter
Posted on Oct 5, 2008 9:16 am
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
jonesy44
Comments: 1,856
 
C++ Snippet:  Temperature Converter
Posted on Oct 5, 2008 4:55 pm
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
ChunkieMonkey
Comments: 127
 
C++ Snippet:  Temperature Converter
Posted on Nov 4, 2008 1:36 am
(late) But great job for what you say is your first...Keep it up!

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom