<As******@msn.c omwrote in message
news:11******** **************@ y66g2000hsf.goo glegroups.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 FahrenheittoCel sius(double)= 0.0; //Function Prototype
This is not a pure virtual method. It is a function prototype. It should
look like this:
double FarenheitToCelc ius(double);
double CelsiustoFahren heit(double)= 0.0;
double CelciusToFarenh eit(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 = FahrenheittoCel sius;
You need to call a function there. Your prototype is:
double FarenheitToCelc ius(double);
so it would be:
Celcius = FarenheitToCelc ius( 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 = CelsiustoFahren heit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
See comments for converting from FarenheitToCelc ius and fix this to reflect.
cout << " Continue? ";
}
return temp;
}
double FahrenheitoCels ius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahren heit (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.