How NOT to comment
This is a mix of several programs turned in in the last few semesters.
The idea is NOT to document every line if it doesn't need it. The idea is NOT to echo the code in the comments. Assume that the reader/grader of the code can understand C++ code. Your job is to tell them WHY you did what you did.
not needed to comment for cin and cout #include <iostream> //included for cin and cout good comment #include <cmath> //included for the pow() function using namespace std; unnecessary comment int main () //my main function { This does not explain the PURPOSE of the variables a better comment is "height is the height of a support" "pounds is for the mass of the concrete of a support in pounds" double height, Rtop, Rbottom, volume, pounds; //declaring variables for the radii, volume, pounds, height, and the constant Pi anyone who can read C++ can understand that a constant is being set up a better comment is "Pi is going to be used for calculating volume of the support" const double Pi = 3.1415927; //declares the variable Pi and assigns it //the constant value of 3.1415927 this one isn't too bad, but "declares the variable bases" is superfluous int bases; //declares the variable bases for the number of bases to calculate for unneeded comment cout << "Concrete Support Calculator" << endl; //title of program unneeded comment cout << endl; //creates a line of space between the title and the calculator unneeded - the prompt says all that is necessary cout << "Enter the top radius of the support (in feet): "; //asks user for top radius unneeded - this tells the user nothing that isn't available from the code itself cin >> Rtop; //assigns user input to the variable "Rtop" unneeded - this tells the user nothing that isn't available from the code itself cout << "Enter the bottom radius of the support (in feet): "; //asks user for bottom radius cin >> Rbottom; //assigns user input to the variable "Rbottom" unneeded - this tells the user nothing that isn't available from the code itself cout << "Enter the height of the support (in feet): "; //asks user for the height of the support cin >> height; //assigns user input to the variable "height" unneeded - this tells the user nothing that isn't available from the code itself cout << "How many supports are you going to build? "; //asks user for the number of supports cin >> bases; //assigns user input to the variable "bases" This is a pretty good comment volume = (Pi * height * (pow(Rtop, 2) + Rtop * Rbottom + pow(Rbottom, 2))) / 3; //calculates the volume of one frustum as per the equation on //http://www.cs.uky.edu/~keen/115/programs/1pgm.html this is a pretty good comment, although 90 really should not be a "naked number" a named constant would be much better pounds = bases * volume * 90; //calculates the number of pounds by multiplying the volume of one base by the number of bases //and then multiplying again by the mass of 1 cubic foot of concrete a decent comment cout << endl; //creates a space between the input and final output All the comments in here are not needed "Report the input values and the calculated values" is about as much as is needed cout << "For " << bases << " column bases (frustum-shaped)," << endl; //outputs the number of bases cout << "with a top radius of " << Rtop << " feet and a bottom radius of " << Rbottom << " feet" << endl; //outputs the two radii cout << "and a height of " << height << " feet," << endl; //outputs the height of the frustum cout << "you need " << pounds << " pounds of concrete." << endl; //outputs the final answer of pounds of concrete needed comment not needed return 0; //returns to the operating system }