C++ programming question Write the C++ source code for this program. Make sure t
ID: 3666059 • Letter: C
Question
C++ programming question
Write the C++ source code for this program. Make sure that it compiles properly and runs exactly as shown above. When the program opens it displays the ID and name, the welcome message, and the please enter line <decimal number> :
You can convert temperature from degrees Celsius to degrees Fahrenheit by multiplying by 9/5 and adding 32. Write a program that allows the user to enter a floating-point number representing degrees Celsius and then displays the corresponding degrees Fahrenheit. Pressing return at the end closes the program.
CUsers Chris AppData Local Temp Rar$EXa0.929 CtoF.exe Student ID: Welcome to the CtoF temperature conversion progran First Last 90012345 This program converts degrees celsius to degrees Fahrenheit Please enter the temperature value in degrees Celsius decimal number): 80.9 The equivalent Fahrenheit temperature is: 177.62 degrees Please enter 'return' to exitExplanation / Answer
// header files
#include <iostream>
#include <iomanip>
#include <string> //needed for strings
using namespace std;
// function prototype
double convertToFahrenheit(double Celsius);
// global variable
double Celsius = 0;
// define main function
int main()
{
// declare local variables
int ID;
string name;
// getting name from user
cout << endl;
cout << "Student name: ";
cin >> name;
// getting Id from user
cout << endl;
cout << "Student ID: ";
cin >> ID;
// instructions
cout<< endl;
cout<<"Welcome to the C to F temperature conversion program";
cout<<endl;
cout<<"This program converts degrees Celsius to degree Fahrenheit";
// asking user to enter celsius value
cout << endl;
cout << "Please enter the temperature value in Celsius <decimal number>: ";
cin >> Celsius;
// output results
//Your program should display both temperatures (with appropriate messages) to 2
//decimal place precision.
cout << endl;
cout << setprecision(2) << fixed;
cout << "The equivalent Fahrenheit temperature is " << convertToFahrenheit(Celsius) << " degree" << endl;
cout << " Press any key to exit";
return 1;
}
// define function
double convertToFahrenheit(double Celsius)
{
//entered to degrees Fahrenheit, using the formula
//Fahrenheit = (9.0/5.0)*Celsius +32.0
double Fahrenheit = 0;
Fahrenheit = (9.0/5.0)*Celsius +32.0;
return Fahrenheit;
}
Sample Output
Student name: FirstLast
Student ID: 90012345
Welcome to the C to F temperature conversion program
This program converts degrees Celsius to degree Fahrenheit
Please enter the temperature value in Celsius <decimal number>: 80.9
The equivalent Fahrenheit temperature is 177.62 degree
Press any key to exit
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.