Use of for to sum sequence of integers

I am spending some time jumping back into C++ as it's been a while and I'm in the process of doing some self study. The problem is as follows:

Write a program that uses a for statement to sum a sequence of integers. Assume that the first integer read specifies the number of values remaining to be entered. Your program should read only one value per input statement. A typical input sequence might be

5 100 200 300 400 500

where the 5 indicates that the subsequent 5 values are to be summed.

I can't seem to understand how for can be used to do this and would like some advice on how to get started, not the answer to the problem since I would like to figure it out. What would be the best way to start the for statement?

Thanks
return 0;
I just figured it out :)

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
#include <iostream>
using namespace std;

int main()
{
	int x; // determines how many times to loop
	int y; // variable to control number of for loops against number of needed integers x
	int j; // integers that will be summed during loop
	int total = 0; // total of all integers

	cout << "How many integers will be summed? ";
	cin >> x;

	for ( y = 1; y <= x; y++ )
	{
		cout << "\nNumber: ";
		cin >> j;
		total += j;
	}

	cout << "\nThe sum of all " << x << " numbers is: " << total << "\n";

	system("pause");
	return 0;
} 
Topic archived. No new replies allowed.