This is a near complete code which is designed to convert fahrenheit or celsius. I face two problem which I'm not sure why its happening.
1. Case I input 1, it executes both case 1 and case 2 becomes an infinity loop. But case I input 2, it only executes case 2 and there's no loop.
2. For some reason, in 'Fahrenheit to Celsius Converter', whatever value I input for fahrenheit, the return value (fahrenheitcelsius) will be zero.
Help. I'm not why its happening.
//converter.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int celsius;
int fahrenheit;
int choice;
int counter = 0;
int celsiusfahrenheit;
int fahrenheitcelsius;
cout << "Please choose your converter by inputting the number '1' or '2'\n";
cout << "\n1. Celsius to Fahrenheit Converter";
cout << "\n2. Fahrenheit to Celsius Converter\n\n";
cout << setw(7);cin >> choice;
while (counter != 1)
{
switch (choice)
{
case 1:
cout << "\nYou are now using: 'Celsius to Fahrenheit Converter'";
cout << "\n\nPlease input temperature in Celsius";
cin >> celsius;
celsiusfahrenheit = celsius * (9/5) + 32;
cout << celsius << " " << celsiusfahrenheit << endl;
++counter;
case 2:
cout << "You are now using: 'Fahrenheit to Celsius Converter'";
cout << "\nPlease input temperature in Fahrenheit";
cin >> fahrenheit;
fahrenheitcelsius = (fahrenheit - 32) * (5/9);
cout << fahrenheit << " " << fahrenheitcelsius << endl;
++counter;
default:
cout << "Please input your choice again";
break;
}
}
}
Okay I fix my loop problem. Now the last problem I have is why whatever value I inputted for fahrenheit (refer to case 2), fahrenheitcelsius (after computing the formula) will always be zero?