I Finished the Code But It Was Different From My Prof's

Hello guys,

My prof put a C++ assignment with a coding template. I need to put the code wherever lines he put the comments beside them. (the comment starts with // ) It was blank beside each // comment before.

The goal is to make the output shows:

"Enter a temperature in degrees Celsius: 23.76
23.76 degrees Celsius is 74.768 degrees Fahrenheit."

I did it with a few references but the thing is I think I put the codes in wrong comments. For instance, the code besides the comment "// prompt user to enter a temperature in degrees Celsius " where I should put "cin << temp_C;" there.

And for the comment, "// read in the temperature in degrees Celsius", I actually don't know what to fill besides it. So I just put "cin << temp_C;" because it works. :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 #include <iostream>

using namespace std;

int main()
{
    
    double temp_C;  // temperature in degrees Celsius
    double temp_F;  // temperature in degrees Fahrenheit
    
    cout << "Enter a temperature in degrees Celsius: ";  // prompt user to enter    a temperature in degrees Celsius  
  	
    cin >> temp_C; // read in the temperature in degrees Celsius
     
    temp_F = 9.0/5.0 * temp_C  + 32; // convert Celsius to Fahrenheit
 
    cout << temp_C << " degrees Celcius is " << temp_F << " degrees Fahrenheit. " << endl;  // display temperature in Celsius and Fahrenheit
    
    return 0;

}


Originally, the assignment is the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main()
{
    
    double temp_C;  // temperature in degrees Celsius
    
    // prompt user to enter a temperature in degrees Celsius 
    cout << "Enter a temperature in degrees Celsius: ";   
  	
    // read in the temperature in degrees Celsius
     
    // convert Celsius to Fahrenheit
 
    // display temperature in Celsius and Fahrenheit
    
    return 0;

}


I hope you guy can help me out. Thank you.
The comments match the code. I think your good. I did not test the code.
But the comment, "// prompt user to enter a temperature in degrees Celsius " originally was above the line " cout << "Enter a temperature in degrees Celsius: ";"

I modified the location to fit my code. *sweating
Your prof won't care. Just as long as the comment is near the line of code it represents.

Most common convention for commentary is to use a end-of-line comment for something that affects only that line:

 
  cout << "Hello world!\n";  // greet the world 


And full-line comments before a block of code:

1
2
3
4
5
6
7
8
9
10
11
12
// The Floyd-Warshall algorithm computes the shortest 
// distances between all vertex pairs of any graph G of size N.
// (Take an algorithms course for more info.)
template <size_t N>
inline
void floyd_warshall( double G[N][N] )
{
  for (size_t i = 0; i < N; i++)
  for (size_t j = 0; j < N; j++)
  for (size_t k = 0; k < N; k++)
    G[j][k] = std::min( G[j][k], G[j][i]+G[i][k] );
}

Hope this helps.
Last edited on
Alright, will see what he'd say later. Many thanks!!
Topic archived. No new replies allowed.