Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

fix this code? #include <iostream> #include<iomanip> using namespace std; float

ID: 655185 • Letter: F

Question

fix this code?

#include <iostream>

#include<iomanip>

using namespace std;

float celsius;

float fahrenheit;

void convertF()

{

            celsius = ((fahrenheit - 32) * 5) / 9;

}

void convertC()

{

            fahrenheit = (((celsius * 9) / 5) + 32);

}

int main()

{

            unsigned short choice;

            cout << "Welcome to the temperature converter. ";

            cout << "Please type '1' for Celsius to Fahrenheit conversion." << endl;

            cout << "Or, type '2' for Fahrenheit to Celsius conversion." << endl;

            cin >> choice;

            switch (choice)

{

            case 1:

            cout << "Please enter your temperature in Celsius. ";

            cin >> celsius;

            convertC();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Fahrenheit is " << fahrenheit << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            case 2:

            cout << "Please enter your temperature in Fahrenheit. ";

            cin >> fahrenheit;

            convertF();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Celsius is " << celsius << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            default:

            cout << "That is not an option!" << endl;

            cout << "Please close the program and try again." << endl;

            break;

}

            return 0;

}

Explanation / Answer

#include <iostream>

#include<iomanip>

using namespace std;

float celsius;

float fahrenheit;

void convertF()

{

            celsius =( ((fahrenheit - 32) * 5) / 9);

}

void convertC()

{

            fahrenheit = (((celsius * 9) / 5) + 32);

}

int main()

{

            unsigned short choice;

            cout << "Welcome to the temperature converter. ";

            cout << "Please type '1' for Celsius to Fahrenheit conversion." << endl;

            cout << "Or, type '2' for Fahrenheit to Celsius conversion." << endl;

            cin >> choice;

            switch (choice)

{

            case 1:

            cout << "Please enter your temperature in Celsius. ";

            cin >> celsius;

            convertC();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Fahrenheit is " << fahrenheit << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            case 2:

            cout << "Please enter your temperature in Fahrenheit. ";

            cin >> fahrenheit;

            convertF();

            cout << " ";

            cout << "Computing... ";

            cout << "The temperature in Celsius is " << celsius << ". ";

            cout << "Press any key to terminate the program." << endl;

            cout << endl;

            break;

            default:

            cout << "That is not an option!" << endl;

            cout << "Please close the program and try again." << endl;

            break;

}

            return 0;

}