Convert Centigrade to Fahrenheit

Hot
Creative Commons License photo credit: saturnism

This programming challenge is from an initial C++ programming course I took in Fall 2007. The Chapter (3) was titled “Expressions and Interactivity”.

I post these old academic challenges for a few reasons. One is to demonstrate my programming learning, experience, and progression. Another reason is to make sure my code and solutions are indexed by search engines, so that other beginning programmers may get help if they need it.

3.10: Write a program that converts centigrade temperatures to Fahrenheit temperatures. The formula is:
F = 9/5 * C + 32
F is the Fahrenheit temperature and C is the centigrade temperature.

My solution:

/* Chapter 3 Challenge 10
Written by Kirk Hingsberger
September 19, 2007
Purpose: Convert Centigrade to Fahrenheit
*/

#include
using namespace std;

int main()
{
float cent, fahr;

cout << "What is the Centigrade temperature?" << endl;
cin >> cent;

fahr = 9 / 5.0 * cent + 32;

cout << cent << " degrees Centigrade equals " << fahr;
cout << " degrees Fahrenheit." << endl;

return 0;
}

Here is the capture script I turned in for grading:

Script started on Thu 20 Sep 2007 09:54:20 AM MDT
$ cat chap3chlg10.cc
/* Chapter 3 Challenge 10
Written by Kirk Hingsberger
September 19, 2007
Purpose: Convert Centigrade to Fahrenheit
*/

#include
using namespace std;

int main()
{
float cent, fahr;

cout << "What is the Centigrade temperature?" << endl;
cin >> cent;

fahr = 9 / 5.0 * cent + 32;

cout << cent << ” degrees Centigrade equals ” << fahr;
cout << ” degrees Fahrenheit.” << endl;

return 0;
}
$ g++ -o chap3chlg10 chap3chlg10.cc -s
$ chap3chlg10
What is the Centigrade temperature?
100
100 degrees Centigrade equals 212 degrees Fahrenheit.
$ exit
exit

Script done on Thu 20 Sep 2007 09:54:50 AM MDT

  • Share/Bookmark




Leave a Reply