Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- float convertFtoC(int temperature);
- int roundUpNextMultiple(int temperature);
- int getInput();
- float convertFtoC(int temperature)
- {
- float celcius (0.0);
- celcius = (temperature - 32.0) * 5.0/9.0;
- return celcius;
- }
- int foundUpNextMultiple(int temperature)
- {
- int addToNextMultiple = temperature % 5;
- if(addToNextMultiple != 0)
- {
- addToNextMultiple = 5 - addToNextMultiple;
- temperature = temperature + addToNextMultiple;
- }
- return temperature;
- }
- int getInput()
- {
- int input;
- cout << "Please enter a temperature greater than 0:\t";
- cin >> input;
- while(input <= 0)
- {
- cout << "Error, please re-enter: ";
- cin >> input;
- }
- return input;
- }
- int main()
- {
- int input = getInput();
- int maxTemp = foundUpNextMultiple(input);
- int start = 0;
- float celcius(0.0);
- cout << "Temperature in F" << "\t" << "Temperature in C\n";
- cout.setf(ios::fixed | ios::showpoint);
- cout.setprecision(2);
- while (start <= maxTemp)
- {
- celcius = convertFtoC(start);
- cout << "\t" << start << "\t\t\t" << celcius << "\n";
- start += 5;
- }
- }
Regards,
Jthep