473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Temperature Conversion Program - Still a Rookie

Hey Everyone~
I'm still a C++ Rookie so please bear with me on this.
I'm doing a temperature conversion program with prototype functions.
Basicly, I was wondering if some of you would take a look at my code
and critique it for me. I'm mostly concerned with how prototype
functions work and if I designed them correctly in my code.
Your participation would be greatly appreciated!

My Code:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

double FahrenheittoCelsius(double)= 0.0; //Function Prototype
double CelsiustoFahrenheit(double)= 0.0;

int _tmain(int argc, _TCHAR* argv[])
{
double tempFahrenheit, tempCelsius;
double temp;
char f;
char c;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius?"; // If user does not specify f or c
ask them
if (temp == f)
{
c = FahrenheittoCelsius;
cout << f " degrees Fahrenheit is" c " degrees celsius ";
cout << " Continue? ";

else
f = CelsiustoFahrenheit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
cout << " Continue? ";

}
return temp;
}
double FahrenheitoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}

Mar 31 '07 #1
21 4234
As******@msn.com wrote:
Hey Everyone~
I'm still a C++ Rookie so please bear with me on this.
I'm doing a temperature conversion program with prototype functions.
Basicly, I was wondering if some of you would take a look at my code
and critique it for me. I'm mostly concerned with how prototype
functions work and if I designed them correctly in my code.
Your participation would be greatly appreciated!

My Code:
I assume you haven't tried to compile this!

Some hints:
#include "stdafx.h"
Non-standard header.
#include <iostream>
#include <cstdlib>

double FahrenheittoCelsius(double)= 0.0; //Function Prototype
double CelsiustoFahrenheit(double)= 0.0;
These are syntax errors, not prototypes. Loose the = 0.0.
int _tmain(int argc, _TCHAR* argv[])
That's _TCHAR? Use

int main( int argc, char* argv[] )

{
double tempFahrenheit, tempCelsius;
double temp;
char f;
char c;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius?"; // If user does not specify f or c
ask them
if (temp == f)
Where is f assigned?
{
c = FahrenheittoCelsius;
Here you attempt to assign a function to a char, which is a very strange
thing to do! Did you mean to write

c = FahrenheittoCelsius( temp );
cout << f " degrees Fahrenheit is" c " degrees celsius ";
cout << " Continue? ";
missing }
else
missing {
f = CelsiustoFahrenheit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
cout << " Continue? ";

}
return temp;
}
double FahrenheitoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}

--
Ian Collins.
Mar 31 '07 #2
<As******@msn.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Hey Everyone~
I'm still a C++ Rookie so please bear with me on this.
I'm doing a temperature conversion program with prototype functions.
Basicly, I was wondering if some of you would take a look at my code
and critique it for me. I'm mostly concerned with how prototype
functions work and if I designed them correctly in my code.
Your participation would be greatly appreciated!

My Code:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

double FahrenheittoCelsius(double)= 0.0; //Function Prototype
This is not a pure virtual method. It is a function prototype. It should
look like this:
double FarenheitToCelcius(double);
double CelsiustoFahrenheit(double)= 0.0;
double CelciusToFarenheit(double);
int _tmain(int argc, _TCHAR* argv[])
This is non standard, becuase you did a windows project and are using
standard headers. That is frowned upon in this newsgroup.

project->properties->c/C++->Precompiled Headers
Change Create/Use Precompiled Header to Not Using Precompiled Header.
Then remove stdafx.cpp from your project. Change your main to:
int main()
{
double tempFahrenheit, tempCelsius;
Better to call these Farenheit and Celcius so you don't confuse yourself.

double Farenheit, Celcious;
double temp;
char f;
char c;
These are not the characters 'f' and 'c' but variables of type char that are
called f and c. You can get rid of these.
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius?"; // If user does not specify f or c
ask them
if (temp == f)
You are asking if temp == f. temp is a double. f is a char. I think you
actually wanted to ask the user but forgot to do it.

char torf;
cin >torf;

if ( torf == 'f' )
{
c = FahrenheittoCelsius;
You need to call a function there. Your prototype is:
double FarenheitToCelcius(double);
so it would be:

Celcius = FarenheitToCelcius( temp );
cout << f " degrees Fahrenheit is" c " degrees celsius ";
That ain't going to work. It should be:
cout << Farenheit << " degrees Fahrenheit is" << Celcius << " degrees
celsius ";
cout << " Continue? ";

else
f = CelsiustoFahrenheit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
See comments for converting from FarenheitToCelcius and fix this to reflect.
cout << " Continue? ";

}
return temp;
}
double FahrenheitoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}
Okay, try all tis, then actually try to compile it. You'll get compilation
errors variables not found, etc.. Fix the errors. If you still get stuck
post again with your new fixed code.
Apr 1 '07 #3
You are a lot of help! And...I feel dumb about some of the mistakes
that I made. I have no clue where I came up with that. But, I'm still
learning. So, here we go. I am having a problem debugging. It won't
execute the program. So, I can build and see the errors that come up
but it won't execute. What am I missing?

Here is my *NEW* code:

// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
cout << " Continue? ";
if
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";
}

return 0;
}
double FahrenheittoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}


Apr 1 '07 #4
As******@msn.com wrote:
You are a lot of help! And...I feel dumb about some of the mistakes
that I made. I have no clue where I came up with that. But, I'm still
learning. So, here we go. I am having a problem debugging. It won't
execute the program. So, I can build and see the errors that come up
but it won't execute. What am I missing?

Here is my *NEW* code:
Which *still* shouldn't compile!
// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
Loose this.
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
cout << " Continue? ";
missing }
if
missing condition and {

--
Ian Collins.
Apr 1 '07 #5
ajk
On 31 Mar 2007 14:22:44 -0700, As******@msn.com wrote:
>#include "stdafx.h"
#include <iostream>
#include <cstdlib>

double FahrenheittoCelsius(double)= 0.0; //Function Prototype
double CelsiustoFahrenheit(double)= 0.0;
double FahrenheittoCelsius(double arg);
double CelsiustoFahrenheit(double arg);
>int _tmain(int argc, _TCHAR* argv[])
{
fine, visual studio will set correct character type depending on
unicode or multibyte but for now use char instead, since you are
learning.
> double tempFahrenheit, tempCelsius;
double temp;
char f;
char c;
initialize all variables always, this can help you in the future,
preferably initialize them to some invalid - for your purposes -
value.
>
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
ok
> cout << " Fahrenheit or Celsius?"; // If user does not specify f or c
ask them
if (temp == f)
{
temp is of type double and f is of type char - what are you doing
here? looks like you have misstakenly taken then variable name f as
the variable value 'f'.

instead use

const char celsius = 'c';
const char fahrenheit = 'f';
char choice;

cin >choice;
if ( choice == celsius )
{
}

> c = FahrenheittoCelsius;
cout << f " degrees Fahrenheit is" c " degrees celsius ";
cout << " Continue? ";

else
f = CelsiustoFahrenheit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
cout << " Continue? ";

}
return temp;
}
double FahrenheitoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}
hth/ajk
Apr 1 '07 #6
ajk
On 31 Mar 2007 22:22:48 -0700, As******@msn.com wrote:
>// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
temp is undefined, it hasn't been set to a value
> cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
cout << " Continue? ";
if
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";
}

return 0;
}
double FahrenheittoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}
Apr 1 '07 #7
<As******@msn.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
You are a lot of help! And...I feel dumb about some of the mistakes
that I made. I have no clue where I came up with that. But, I'm still
learning. So, here we go. I am having a problem debugging. It won't
execute the program. So, I can build and see the errors that come up
but it won't execute. What am I missing?

Here is my *NEW* code:

// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
You don't need to include stdafx.h anymore, that was part of precompiled
headers. Delete that line.
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >corf;
You send the message to the console for the user to enter the Temperature,
but then you have them input if it's celsius or centigrade.

This should be:

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << "Celcius or Farenheit? ";
cin >corf;
if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
cout << " Continue? ";
if
Somehow you cut off this line. This should probably be:
if ( corf == 'c' )
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";
}

return 0;
}
double FahrenheittoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}

Apr 1 '07 #8
Jim Langston wrote:

You send the message to the console for the user to enter the
Temperature, but then you have them input if it's celsius or
centigrade.

This should be:

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << "Celcius or Farenheit? ";
cin >corf;
if (corf == 'f')

This isn't a very robust design. There are all kinds of unused
characters left hanging around. I'd recommend reading in the entire
line and examining the first character.


Brian
Apr 1 '07 #9
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.
Ok....so,I started playing around with it and I got the program to
finally compile and it is working fairly ok.
The program will exit when I enter a value because temp,
tempFahrenheit, and tempCelsius have not been intialized. When I set
it to 0 I still get the same problem. Any ideas?
Oh by the way....here is the updated code from this afternoon.

// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
cout << " Continue? ";

}
if (corf == 'c')
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";

}

return temp;
}
double FahrenheittoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}



Apr 1 '07 #10
As******@msn.com wrote:
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.
Nonsense.
Ok....so,I started playing around with it and I got the program to
finally compile and it is working fairly ok.
The program will exit when I enter a value because temp,
tempFahrenheit, and tempCelsius have not been intialized. When I set
it to 0 I still get the same problem. Any ideas?
It will exit because it falls out of main, there is nothing after your
last output line.
Oh by the way....here is the updated code from this afternoon.

// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
You don't use anything from <cstdlib>, so it can go as well.
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
You don't initialise tempFahrenheit, so garbage will be output, same
fortempCelsius in the next block.
cout << " Continue? ";
You could do the above after the if() blocks to avoid duplication.
}
if (corf == 'c')
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";

}

return temp;
This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.

--
Ian Collins.
Apr 1 '07 #11
On Apr 1, 4:56 pm, Ian Collins <ian-n...@hotmail.comwrote:
Ashee...@msn.com wrote:
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.

Nonsense.
Ok....so,I started playing around with it and I got the program to
finally compile and it is working fairly ok.
The program will exit when I enter a value because temp,
tempFahrenheit, and tempCelsius have not been intialized. When I set
it to 0 I still get the same problem. Any ideas?

It will exit because it falls out of main, there is nothing after your
last output line.
Oh by the way....here is the updated code from this afternoon.
// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>

You don't use anything from <cstdlib>, so it can go as well.


using namespace std;
double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);
int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;
if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";

You don't initialise tempFahrenheit, so garbage will be output, same
fortempCelsius in the next block.
cout << " Continue? ";

You could do the above after the if() blocks to avoid duplication.
}
if (corf == 'c')
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";
}
return temp;

This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.

--
Ian Collins.- Hide quoted text -

- Show quoted text -
I hear ya...but it won't go any further until I intialize that
variable.

Apr 1 '07 #12
As******@msn.com wrote:
>>You don't initialise tempFahrenheit, so garbage will be output, same
fortempCelsius in the next block.

>> cout << " Continue? ";

You could do the above after the if() blocks to avoid duplication.

>> }
if (corf == 'c')
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
cout << " Continue? ";
>> }
>> return temp;

This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.

--
Ian Collins.- Hide quoted text -

- Show quoted text -
Please don't quote signatures, or that google quoted text crap.
>
I hear ya...but it won't go any further until I intialize that
variable.
What won't? Looking though what you posted, it will run through once,
then exit.

--
Ian Collins.
Apr 1 '07 #13
As******@msn.com wrote:
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.
That's only because you started with the wrong sort of project
initially. If you can't fix it by changing the project settings, start
over with a new "console" project and include that file in the new
project.


Brian
Apr 1 '07 #14
On Apr 2, 8:56 am, Ian Collins <ian-n...@hotmail.comwrote:
Ashee...@msn.com wrote:
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.

Nonsense.
How do you know whether or not the OP's compiler will compile
code without that line? In fact it seems likely from his
description that the compilation fails when he deletes it.
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";

You don't initialise tempFahrenheit, so garbage will be output
The behaviour will be undefined -- it could crash the program, etc.
return temp;

This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.
Other return values are legal. The only 'problem' is that the
operating system may not be able to determine whether the
program succeeded or failed.

Apr 2 '07 #15
Old Wolf wrote:
On Apr 2, 8:56 am, Ian Collins <ian-n...@hotmail.comwrote:
>>Ashee...@msn.com wrote:
>>>Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.

Nonsense.

How do you know whether or not the OP's compiler will compile
code without that line? In fact it seems likely from his
description that the compilation fails when he deletes it.
He made no mention of a complier, just that the code wouldn't compile
without it. On my system, it won't compile with it!

--
Ian Collins.
Apr 2 '07 #16
<As******@msn.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.
Make sure you remove the stdafx.cpp from the progject and it should. This
code does for me in VC++ .net 2003 without stdafx.h
Ok....so,I started playing around with it and I got the program to
finally compile and it is working fairly ok.
The program will exit when I enter a value because temp,
tempFahrenheit, and tempCelsius have not been intialized. When I set
it to 0 I still get the same problem. Any ideas?
Oh by the way....here is the updated code from this afternoon.
Run the program with ctrl-F5 instead of F5 and you will get a
Press any key to continue...
after the program runs allowing you to see the output. This is Microsoft
specific.

Personally, I just make it wait in code by putting at the end of main
something on the line of:
std::string wait;
std::getline( std::cin, wait );
>
// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

double FahrenheittoCelsius(double); //Function Prototype
double CelsiustoFahrenheit(double);

int main()
{
double tempFahrenheit, tempCelsius;
double temp;
char corf;

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
Okay, the temperature is entered into a variabled called "temp".
cout << " Fahrenheit or Celsius? ";
cin >corf;

if (corf == 'f')
{
tempCelsius = FahrenheittoCelsius( temp );
cout << tempFahrenheit << " degrees Fahrenheit is" << tempCelsius
<< " degrees celsius ";
The variable "tempFahrenheit" is not being used. The value was stored in
temp, not tempFahrenheit.
cout << temp << " degrees Fahrenheit is" << tempCelsius << " degrees
celsius ";
}
if (corf == 'c')
{
tempFahrenheit = CelsiustoFahrenheit(temp);
cout << tempCelsius << " degrees Celsius is " << tempFahrenheit << "
degrees Fahrenheit";
Same here, output temp, not tempCelsius.
cout << " Continue? ";

}

return temp;
}
double FahrenheittoCelsius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahrenheit (double c)
{
return (9/5.0 * c) + 32;
}

Apr 2 '07 #17
On Apr 1, 8:40 pm, "Default User" <defaultuse...@yahoo.comwrote:
Jim Langston wrote:
You send the message to the console for the user to enter the
Temperature, but then you have them input if it's celsius or
centigrade.
This should be:
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << "Celcius or Farenheit? ";
cin >corf;
if (corf == 'f')

This isn't a very robust design. There are all kinds of unused
characters left hanging around. I'd recommend reading in the entire
line and examining the first character.
The first non-blank character, and then verifying that there
aren't any other non-blanck characters in the line:-).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 2 '07 #18
On Apr 1, 10:56 pm, Ian Collins <ian-n...@hotmail.comwrote:
Ashee...@msn.com wrote:
Alright guys....
I agree with you that stdafx.h does not need to be included but it
won't compile without it.
Nonsense.
Worse. On my systems, it won't compile with it.

[...]
return temp;
This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.
Just a nit: it's legal, temp is a double, and a double converts
implicitly to an int. It doesn't make any sense, and the
results are very much implementation defined, but it is legal.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 2 '07 #19
James Kanze wrote:
On Apr 1, 10:56 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>This isn't a legal return value from main, 0, EXIT_SUCCESS and
EXIT_FAILURE are the only portable returns.


Just a nit: it's legal, temp is a double, and a double converts
implicitly to an int. It doesn't make any sense, and the
results are very much implementation defined, but it is legal.
You're right, I should have written "portable" rather than "legal".
--
*Please* fix this - it's a pain to have to keep manually trimming your
signature.

--
Ian Collins.
Apr 2 '07 #20
Ian Collins wrote:
James Kanze wrote:
--

Please fix this - it's a pain to have to keep manually trimming your
signature.
Heh, I was going to mention that as well. James, your .sig separator is
missing a character. It should be "-- " (dash dash space).


Brian
Apr 2 '07 #21
Thank you guys!
Your criticism and suggestions helped me! I appreciate you guys taking
the time to critique me! I got it to work finally!

And I found this funny....
"He made no mention of a complier, just that the code wouldn't
compile
without it. On my system, it won't compile with it!

--
Ian Collins. "

Hahaha...I'm a girl. So..."She made no mention....". ;) Just thought
I'd let ya know Ian!

But, again, I appreciate all of your help!

~Ashley~

So, here is the final code:
// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;

float FahrenheittoCelsius(float f); //Function Prototype
float CelsiustoFahrenheit(float c);
float result = 0;
int main()
{
float tempFahrenheit = 0;
float tempCelsius = 0;
float temp = 0;
char corf = 'f';
char yorn = 'y';

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;
if (corf == 'f')
{
FahrenheittoCelsius(temp);
cout << temp << " degrees Fahrenheit is" << result << " degrees
celsius " << endl;
}
else if (corf == 'c')
{
CelsiustoFahrenheit(temp);
cout << temp << " degrees Celsius is " << result << " degrees
Fahrenheit" << endl;
}

cout << " Continue? Y or N ";
cin >yorn;
while (yorn == 'y')
{
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;

if (corf == 'f')
{
FahrenheittoCelsius(temp);
cout << temp << " degrees Fahrenheit is" << result << " degrees
celsius " << endl;
}
else if (corf == 'c')
{
CelsiustoFahrenheit(temp);
cout << temp << " degrees Celsius is " << result << " degrees
Fahrenheit" << endl;
}
cout << " Continue? Y or N ";
cin >yorn;
}

while (yorn != 'n')

return 0;
}
float FahrenheittoCelsius (float f)
{
result = 5.0 / 9.0 * (f - 32);
return result;
}
float CelsiustoFahrenheit (float c)
{
result = (9.0 / 5.0 * c) + 32;
return result;
}




Apr 3 '07 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Derek Ross | last post by:
Hello, Say I have a server that's saving the CPU temperature to 'temperature.js' once a second. The contents of the file is one single line: var temperature = "35.5"; And it changes as...
1
by: deanfamily11 | last post by:
I'm trying to have this program do a simple temperature conversion from Fahrenheit to Celsius. I have confirmed that the other variable is receiving and calculating the conversion, but it is just...
5
by: anthony | last post by:
One the computer I am programmig I could see the CPU temperature in the BIOS, is there a system DLL in VB.NET that I can call to display the temperature in my software? Thanks!
7
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the...
1
by: pollardw | last post by:
i have written a small program to convert Fahrenheit to Celsius and I have a minor problem. Here is the code what do i need to change to get it to work? /* Convert Fahrenheit to Celsius */ ...
4
by: arnuld | last post by:
this is my final code. Can you folks advise some improvements for making this programme better? BTW, i aways compile my programme with this cmmand on Linux: g++ -ansi -pedantic -Wall -Wextra...
16
by: Brigitte Behrmann | last post by:
I am absolutely stuck with this one. I have to create a temperature conversion calculator that rounds the resulting temperature to the nearest whole number & vice versa. The result must be displayed...
1
by: vbfrnd | last post by:
I need to write a program where I have to convert a temp provided by user to celcius or farenheit and vice versa. I am using text boxes to get the temp in degrees but when I am trying to convert the...
25
by: kid joe | last post by:
Hi, Is it normal for the temperature of your CPU to increase as time goes on? I've got an Athlon XP 2100+ and I see that the temp is now at 51C where it used to be around 42 to 44. Anyone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.