SRL Archive - C/C++ Help and Tutorials

Fahrenheit to Celsius Converter


Overtime

2011-09-12 22:30:27

Not due till next Wednesday, but I love being ahead of everyone in the class.

As it is, everyone knows I got some knowledge under my belt on this stuff so everyone is turning to me for questions.

I feel like a boss :spot:

/*
// Name: James Luna
// ID #:
// Date: September 12, 2011
//
// CSCI / CMPE 1370.03
// Assignment 1: Fahrenheit to Celsius converter
// Due Date: September 21, 2011
//
// This program converts a temperature in Fahrenheit to Celsius
// The formula is: C = 5 / 9 (F - 32)
*/

/* Our includes we will be using for the program
*/
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;


int main()

{
/* Our doubles we will be using, so we can use them later.
*/
double celsius, fahrenheit;


/* My introduction to the user using my program.
*/
cout << " *James Luna's Fahrenheit to Celsius Converter*"
<< endl
<< endl
<< endl;

/* Asking the user to input his data in Fahrenheit
*/
cout << " Enter a temperature in Fahrenheit: ";
cin >> fahrenheit;
cout << endl;

/* The forumula to use to get our celsius degree
I added a .0 so that it can take it as a double.
*/
celsius = 5.0 /9 * (fahrenheit - 32);

/* So we can set how many deciamls we want it to show to the right
*/
cout << setprecision(1) << fixed;

/* This is going to tell the user what data he inputed then display the
degree in celsius.
*/
cout << " " << fahrenheit << " degrees Fahrenheit is " << celsius << " degrees Celsius. "
<< endl
<< endl
<< endl;

/* My closing statement, thanking the user for trying out my program
*/
cout << " Thank You for using my Fahrenheit to Celsius converter. "
<< endl
<< endl
<< endl;

/* Asking the console to pause so the user can see the data. */
system ("Pause");
return 0;
}

NCDS

2011-09-12 22:39:18

I'm certainly no pro in c++, but for this:

/* Asking the console to pause so the user can see the data. */
system ("Pause");
Why wouldn't you just use cin.get(); ? (I mean that as more of a question, honestly.)

Overtime

2011-09-12 22:44:14

I've already been asked this a million times. lol.

She wants us to use "pause" as our method for now.

Once we get into looping she will show us other methods how to end or restart our program.

Gu3st...

2011-09-13 03:48:13

Lol, she's a bitch.

Nice program Squancy :p

Overtime

2011-09-13 08:19:12

Yea otherwise i would use

get.ignore();
get.cin();
So much cleaner.

And thankyou again zytex lol

Echo_

2011-09-16 12:18:06

Are you going through C++ Primer Plus by Stephen Prata? Because I swear you and I have had the exact same assignments.

I know what you mean about people asking you questions though, even the teacher thinks I'm leet because I know how to write Pascal code :D

sf411

2011-09-16 12:29:04

Not that it matters, Overtime, but why use /* */ on single line comments instead of //?