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.