From the FAQ:
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Also, as a general comment, you can improve your commenting style. A comment shouldn't simply restate one line of code. If your code is so obfuscated that you need a comment line to explain every line, then rewrite your code to be more clear.
And you are using old headers. This is a little better:
Code:
#include <iostream>
using namespace std;
/* main()
Program entry point. Queries the user for their age, and
outputs a text message depending on the value they enter.
Parameters: None
Returns: 0
*/
int main()
{
int age;
cout<<"Please input your age: ";
cin>>age;
if(age<100)
{
cout<<"You are pretty young!";
}
else if(age==100)
{
cout<<"You are old";
}
else
{
cout<<"You are really old";
}
return 0;
}
One acceptable use of comments for small sections of code is to name the parameters of a messy function, like WinAPI calls. For example, this:
Code:
HANDLE h = CreateFile(
"c:\\file.txt", // file name
GENERIC_READ, // Access permissions
0, // Share mode
NULL, // Pointer to security attributes
OPEN_EXISTING, // Open vs. create options
0, // Flags
NULL // Handle to template file
);
Good comments:
* Summarize a function or portion of a function, or
* Summarize the parameters or returns of a function, or
* Provide information that otherwise would not be obvious
In this case, my commented version of your code does the first 2 (it allows you to discern the purpose of the function) and my WinAPI comment serves the third purpose. You could not look at, for example, the Share Mode parameter and know what it was, except for the comment that says it is share mode.