Is program correct?

I created a program and want to make sure it's correct. The original prompt is :Write a program called Lab11.cpp that reads a Fahrenheit degree as an input from the user, then converts it to Celsius and produces the desired output similar to Figure 1. The formula for the conversion is as follows, where C is Celsius and F is Fahrenheit:
C= 5/9*(F-32)
Hint: In C++, 5 / 9 is 0, but 5 / 9.0 is 0.55555. Create double variables for celsius and fahrenheit, and force floating point division by using a decimal number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// CS 1336
// Lab 11
/*
 * C++ Program to Perform Fahrenheit to Celsius Conversion
 */

#include <iostream>
using namespace std;

double fahrenheitToCelsius(double fahrenheit)
{
    double celsius;

    celsius = 5.0 / 9.0 *(fahrenheit - 32.0);
    return celsius;
}

int main()
{
    double fahrenheit;

    cout << " CS 1336 - Lab 11" << endl << endl;
   
    cout << "Enter temperature in Fahrenheit: ";
    cin >> fahrenheit;
  
    cout << endl << endl; 
    
    cout << fahrenheit << " degree Fahrenheit is " << fahrenheitToCelsius(fahrenheit) << " degree Celsius." << endl << endl;

    return 0;
Is program correct?

Functionally the program is correct, though I'd probably do a bit of rework to make it less verbose.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

double fahrenheitToCelsius(double fahrenheit)
{
   return (5.0 / 9.0 * (fahrenheit - 32.0));
}

int main()
{
   std::cout << "CS 1336 - Lab 11\n\n";

   std::cout << "Enter temperature in Fahrenheit: ";
   double fahrenheit;
   std::cin >> fahrenheit;

   std::cout << '\n' << fahrenheit << " degree Fahrenheit is "
             << fahrenheitToCelsius(fahrenheit) << " degree Celsius.\n";
}
CS 1336 - Lab 11

Enter temperature in Fahrenheit: 98.6

98.6 degree Fahrenheit is 37 degree Celsius.
Topic archived. No new replies allowed.