#include // Function declarations int main(); // Function definitions // This program asks the user to enter a temperature and // then asks whether that temperature is in degrees Celsius // or degrees Fahrenheit. // // If the temperature is in degrees Celsius, the program // converts it to degrees Fahrenheit and prints the result. // Otherwise, the temperature is in degrees Fahrenheit, so // the program converts it to degrees Celsius and prints // the result. // // Run this program using several different sample inputs // and determine whether it works correctly. // // Choose test cases for which you know the expected results. // Be sure to test both conversions: // // Celsius -> Fahrenheit // Fahrenheit -> Celsius // // If the program works correctly, document the test cases // you used and the results you expected. // // If the program does not work correctly, identify the // problem, fix the bug, and test the program again. // // This question was designed with help from Wani Gupta. int main() { while ( true ) { double temp{}; std::cout << "Enter a temperature (Celsius or Fahrenheit): "; std::cin >> temp; bool in_celsius{}; std::cout << "Is this temperature in Celsius?" << std::endl; std::cout << " Enter 1 for yes, 0 for no: "; std::cin >> in_celsius; if ( in_celsius ) { // 9 // T = --- T + 32 // F 5 C temp = (9/5)*temp + 32; std::cout << "The temperature in Fahrenheit is " << temp << std::endl; } else { // 5 // T = --- (T - 32) // C 9 F temp = (5/9)*(temp - 32); std::cout << "The temperature in Celsius is " << temp << std::endl; } std::cout << std::endl; } return 0; }