need help!! we are using c++ for this program. Write a program that will first a
ID: 3788671 • Letter: N
Question
need help!! we are using c++ for this program.
Write a program that will first allow a user to choose one of two options: 1. Convert a temperature from degrees Celsius to degrees Fahrenheit. 2. Convert a temperature from degrees Fahrenheit to degrees Celsius. The program should then prompt for the temperature value to be entered and output the new value that results from the conversion. To convert from Celsius to Fahrenheit you can multiply the value by 1.8 and then add 32. To convert from Fahrenheit to Celsius, you can subtract 32 from the value, then multiply by 5 and divide the result by 9 Screen Output Examples 1. degree C to degree FExplanation / Answer
#include <iostream>
using namespace std;
double convert(double temp, int type){
if(type == 1) return temp * 1.8 + 32;
else return ((temp - 32) * 5.0) / 9.0;
}
int main(){
double temp;
int choice;
cout << "This program can do the following: 1. Convert from degrees Centigrade to degrees Fahrenheit 02. Convert from degrees Fahrenheit to degrees Centigrade Select the conversion (1 or 2): ";
cin >> choice;
cout << "Enter a temperature in degrees ";
if(choice == 1) cout << "Centigrade: ";
else cout << "Fahrenheit: ";
cin >> temp;
cout << "That is equivalent to " << convert(temp, choice) << " ";
if(choice == 2) cout << "Centigrade: ";
else cout << "Fahrenheit: ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.