SRL Archive - C/C++ Help and Tutorials

Celsius to Fahrenheit Converter


Overtime

2011-08-18 17:46:07

Hello guys! As many of your know im attending school and majoring in Computer Science.

I'm getting a semester and a half start on programming as In Spring of 2011 i will be taking programming classes.

So with this i introduce my Celsius to Fahrenheit Converter!

I just created this with a help of a book, called "C++ For Dummies" :P

Lol but yes i just made it and im starting to understand it more, which in turn may lead to finally start programming for SRL :O

Go ahead and scan you wont find anything lol, im just a beginner :stirthepot:

http://www.mediafire.com/?28sl4n55dok9c8j

i luffs yeww

2011-08-18 17:50:39

sawse pl0x.

Overtime

2011-08-18 17:52:56

[php]

//
// Program to convert tempature from Celsius degree
// units into Fahrenheight degree units:
// Fahrenheight= Celsius * (212-32)/100 + 32
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// enter the tempature in Celsius
int celsius;
cout << "Enter the tempature in Celsius:";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results (Followed by a newline)
cout << "Fahrenheit value is:";
cout << fahrenheit << endl;

// wait unitil user is ready before terminating program to allow the user to
// see the program results
system("PAUSE");
return 0;
}

[/php]

i luffs yeww

2011-08-18 18:03:16

I don't like how you're pushing to cout. ;<

Not that it really matters, but just curious as to why it's not on one line.

Other than that, try some formatting. :) Give it some other values to output (Kelvin, the closest boiling point of an element to the number inputted, average rain fall of the month of the average temperature inputted, etc.). Not that any of that is super realistic, but it would give you some more things to mess with (string formatting, loops, exceptions, etc.).

Good work.

EDIT:

Also not sure why you're using system("PAUSE");.. I'd do something like..

cout << "Press \'Enter\' to terminate << endl;
if (getc(cin) == #13){ // (or whatever the params are or anything.. haven't messed with C++ in a bit)
do whatever. // again, don't recall. :p sorry.
}

Overtime

2011-08-18 18:06:43

yea its the way this book is showing me, im going to play with some other math functions and see what other calculators i can come up with. Maybe the Quadratic Formula, since i have been playing with that for a while now.

This is barley chapter 1 of 30.

Just now getting to chapter 2!

x[Warrior]x3500

2011-08-18 19:23:57

From: i luffs yeww
system("PAUSE");]


ewwwww
i always just used cin.get();

edit: nice job though :) ur going to love C++

Naum

2011-08-18 22:43:12

-273 from celsius, afaik, and you've got Kelvin :). Gj!

i luffs yeww

2011-08-18 22:48:09

0 celsius is 273.15K, iirc. So celsius + 273.15 == Kelvin.

Absolute zero is -273.15c.

Naum

2011-08-18 22:51:51

From: i luffs yeww
0 celsius is 273.15K, iirc. So celsius + 273.15 == Kelvin.

Absolute zero is -273.15c.


this