0

I am a novice C++ programmer. Only started learning this week, my apologies ahead of time if this is a simple fix.

I am creating a system that will allow users to convert from either Celsius or Fahrenheit to their chosen system until they decide to quit.

I have tried moving the choice answer to the bottom of the while loop so it can use the new input to switch to another converter or quit. However, it spasms and assumes the input is 0.

double fToC(double temp) {
   some code
}

double cToF(double temp) {
   some code
}

int main()
{
string choice;
double numChoice;
cout << "Convert from [C]elsius, [F]ahrenheit, or [Q]uit?: " << endl;
getline (cin, choice);
char choiceChar = choice[0];
while (choiceChar != 'Q' || choiceChar != 'q') {
    if (choiceChar == 'c' || choiceChar == 'C') {
    cout << "Enter a number!" << endl; 
    cin >> numChoice;
    double newTemp = cToF(numChoice);
    cout << numChoice << " Celsius is " << newTemp << " Fahrenheit" << endl;
} else if (choiceChar == 'f' || choiceChar == 'F') {
    cout << "Enter a number!" << endl; 
    cin >> numChoice;
    double newTemp = fToC(numChoice);
    cout << numChoice << " Fahrenheit is " << newTemp << " Celsius" << endl;
     }
     cout << "Convert from [C]elsius, [F]ahrenheit, or [Q]uit?: " << endl;
     getline (cin, choice);
     char choiceChar = choice[0];
}
cout << endl << "Exiting...";
return 0;

}

On the first conversion, it will accurately convert. For example, fToC using the value 32 will produce 0 Celsius. If you want to switch to cToF, it will continuously convert 0f to Celsius until you force close the terminal.

Kelsie
  • 33
  • 8

0 Answers0