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

Write a C++ program that accepts a number followed by one space and then a lette

ID: 3634012 • Letter: W

Question

Write a C++ program that accepts a number followed by one space and then a letter. If the letter following the number is f or F, the program is to treat the number entered as a temperature in degrees Fahrenheit, convert the number to the equivalent degrees Celsius, and print a suitable display message. If the letter following the number is c or C, the program is to consider the number entered as a Celsius temperature, convert the number to the equivalent degrees in Fahrenheit, and print a suitable display message. while the letter is neither f (F) nor c (C) the program is to print a message that the data entered is incorrect and terminate. The conversion formulas:
celsius = (5.0/9.0) * (fahrenheit - 32.0)
fahrenheit = (9.0/5.0) * celsius + 32.0

re-write the program using a switch statement instead of a if-else chain in Visual C++ 2010

Explanation / Answer

please rate - thanks

with input as requested, using only switch, no if

#include<iostream>
using namespace std;
int main()
{char type;
double temp,newTemp;
cout<<"Enter a temperature follewed by space and a c or f: ";
cin>>temp>>type;
switch(type)
   {case 'c':
    case 'C': newTemp=(9.0/5.0)*temp+32.0;
              cout<<temp<<" degrees celsius="<<newTemp<<" degrees fahrenheit ";
              break;
    case 'f':
    case 'F': newTemp=(5.0/9.0)*(temp-32.0);
               cout<<temp<<" degrees fahrenheit="<<newTemp<<" degrees celsius ";
               break;
    default: cout<<"Invalid temperature type ";
    }
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote