So I have my latest assignment almost complete but when I enter the EOF the program kicks into an endless loop? I have found that I can tend to get a little "curly brace crazy" so I'm not sure if thats the issue I'm running into or if it's something else. I have the EOF command in lines 46,57,93. Here's the code:
// Temperature Conversions Algorithm
// 1. Declare function prototypes
// 2. Input and calculate variables in main function
// 3. Construct "do_while" loop for main function
// 1. Include "EOF" termination
// 4. Welcome user to program
// 5. Prompt user to enter value in Farenheit
// Loop
// Calculate the value in Farenheit and return in Celsius
// Prompt user to enter value in Celsius
// Calculate the value in Celsius and retun in Farenheit
// End Algorithm for Temperature Conversions
#include <iostream>
#include <iomanip>
usingnamespace std;
// Function Prototypes
double farenConvert (double f, double c);
double celConvert (double c, double f);
// Define Variables
double f, c;
char retry = 'Y' || 'y';
int main()
{
cout << "Welcome to the Temperature Converter.\n" << endl << endl;
do
{
// Farenheit to Celsius conversion
cout << "Please enter a number in Farenheit that you would " <<
"like to convert to Celsius: " << endl << endl;
{
cin >> f;
if (!cin.eof())
cout << fixed << showpoint << setprecision(1);
cout << "The answer is: " << celConvert (f ,c) << endl << endl;
// Celsius to Farenheit conversion
cout << "Please enter a number in Celsius that you would " <<
"like to convert to Farenheit: " << endl << endl;
cin >> c;
if (!cin.eof())
cout << "The answer is: " << farenConvert (f , c) << endl << endl;
cout << "Would you like to do another conversion? (Y/N)" << endl;
cin >> retry;
}
// Celsius Conversion Function
double celConvert (double f, double c);
{
double celConvert;
celConvert = ((f - 32) / 180.00) * 100.00;
}
// Fahrenheit Conversion Function
double farenConvert (double f, double c);
{ // line 92
double farenConvert;
farenConvert = 32 + c * (180.00 / 100.00);
} while (!cin.eof());
}
system ("pause");
return 0;
}
You've declared the functions celConvert and farenConvert inside of main. They are seperate, and if you have { stuff } right after you don't need the semicolon.
Thanks to the both of you. I got my original issue worked out but now those updates have caused my temperature conversions to all return a "1. $" (or other random symbol). Any idea what could be causing this? The function definitions are lines 70-88.
// Temperature Conversions Algorithm
// 1. Declare function prototypes
// 2. Input and calculate variables in main function
// 3. Construct "do_while" loop for main function
// 1. Include "EOF" termination
// 4. Welcome user to program
// 5. Prompt user to enter value in Farenheit
// Loop
// Calculate the value in Farenheit and return in Celsius
// Prompt user to enter value in Celsius
// Calculate the value in Celsius and retun in Farenheit
// End Algorithm for Temperature Conversions
#include <iostream>
#include <iomanip>
usingnamespace std;
// Function Prototypes
double farenConvert (double f, double c);
double celConvert (double c, double f);
// Define Variables
double f, c;
char retry = 'Y' || 'y';
int main()
{
cout << "Welcome to the Temperature Converter.\n" << endl << endl;
do
{
// Farenheit to Celsius conversion
cout << "Please enter a number in Farenheit that you would " <<
"like to convert to Celsius: " << endl << endl;
cin >> f;
if (!cin.eof())
cout << fixed << showpoint << setprecision(2);
cout << "The answer is: " << celConvert (f ,c) << endl << endl;
// Celsius to Farenheit conversion
cout << "Please enter a number in Celsius that you would " <<
"like to convert to Farenheit: " << endl << endl;
cin >> c;
if (!cin.eof())
cout << "The answer is: " << farenConvert (f , c) << endl << endl;
cout << "Would you like to do another conversion? (Y/N)" << endl;
cin >> retry;
} while (!cin.eof());
system ("pause");
return 0;
}
// Celsius Conversion Function
double celConvert (double f, double c)
{
double celConvert;
celConvert = ((f - 32) / 180.00) * 100.00;
}
// Farenheit Conversion Function
double farenConvert (double f, double c)
{
double farenConvert;
farenConvert = 32 + c * (180.00 / 100.00);
}
First off, how come your celConvert has a c parameter and farenConvert has an f parameter? These are unnecessary since the function is returning this value.
This leads to the answer, your functions aren't returning anything. I don't see how your compiler didn't catch this?