Am I explaining and doing this correctly?

Am I explaining and doing this correctly?

Also can someone give me more tips when commenting like when to comment and when no to? I don't know but sometimes I just comment the obvious.

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
32
33
34
35
36
37
#include <iostream>

using namespace std;

int main()
{

	// Ask user how many numbers he would like to store in allocated memory
	cout << "How many numbers would you like to enter? : ";

	// Create and initialize variables
	int amount = 0, number = 0;

	// Get user's amount number
	cin >> amount;

	// Create a pointer and point it to a new allocated memory for the amount input
	int *input = new (nothrow) int[amount];

	// Loops through the amount of allocated memory held and set values to them all
	for (number = 0; number < amount; ++number) {
		cout << "Enter number : ";
		cin >> input[number];
	}

	// Finally prints the outcome
	cout << "You entered : ";

	for (number = 0; number < amount; ++number) {
		number != (amount - 1) ? cout << input[number] << ", " : cout << input[number] << ".\n";
	}

	// Delete the allocated memory once finished with it
	delete[] input;

	return 0;
}
Comment what you don't find obvious. Your comments before loops are okay. Also, line 30 needs clarification. I suppose if you wrote it as an if-else statement, it would be best, but a comment wouldn't hurt either. Generally, it might be a good idea to only leave a comment before every function.
Topic archived. No new replies allowed.