i dont understand

the program itself works well; however, only for works, the other does not execute. Yet i do not want the loop to showChoices(); during the for loop. What i really want to know is why the second for does not execute.

#include <iostream>
#include <iomanip>

using namespace std;

void showChoices();

void fahrenheitToCelsius(double& fahrenheit, double& celsius);

void celsiusToFahrenheit(double& celsius, double& fahrenheit);

int main()
{
int choice;
double fahrenheit, celsius;

showChoices();
cin >> choice;
cout << endl;

while (choice != 99)
{
if (choice == 1)
{
system("cls");

fahrenheitToCelsius(fahrenheit, celsius);

system("cls");
cout << "CONVERSION COMPLETE!" << endl;
cout << endl;
cout << "Fahrenheit Degrees: " << fahrenheit << endl;
cout << endl;
cout << "Celsius Degrees: " << celsius << endl;

showChoices();
cin >> choice; // this for executes
}
else if (choice == 2)
{
system("cls");
celsiusToFahrenheit(celsius, fahrenheit);

system("cls");
cout << "CONVERSION COMPLETE!" << endl;
cout << endl;
cout << "Celsius Degrees: " << celsius << endl;
cout << endl;
cout << "Fahrenheit Degrees: " << fahrenheit << endl;
} // this for does not
else
{
system("cls");
cout << "Unfortunatly this is not a choice, please try again!" << endl;
showChoices();
}
}

system("pause");

return 0;
}

void showChoices()
{
cout << setfill('*') << setw(37) << "*" << endl; //creates a decorative line consisting of only *
cout << setw(10) << "Welcome to the Temparature Converter!" << endl;
cout << setfill('*') << setw(37) << "*" << endl;//creative boarder
cout << endl;
cout << endl;

cout << "To convert Fahrenheit to Celsius press 1." << endl;
cout << endl;
cout << "To convert Celsius to Fahrenheit press 2." << endl; //give the user the options they have in this program
cout << endl;

cout << "To Stop the program press 99." << endl;
cout << endl;
cout << "What is your choice? ";
}

void fahrenheitToCelsius(double& fahrenheit, double& celsius)
{
system("cls");// clears the screen

cout << "Enter Fahrenheit degree to the nearest whole number: ";
cin >> fahrenheit;
cout << endl;
celsius = ((fahrenheit - 32) * 5) / 9; //converts Fahrenheit to Celsius
}

void celsiusToFahrenheit(double& celsius, double& fahrenheit)
{
system("cls");
cout << "Enter Celsius degree to the nearest whole number: ";
cin >> celsius;
cout << endl;
fahrenheit = (((celsius * 9) / 5) + 32); //calculation for Celsius to Fahrenheit
}
Can you put your code in [code] tags and indent it?
When choice is 2, you don't give the user a chance to enter another value, so choice remains 2 forever.

Topic archived. No new replies allowed.