Adding integers

Hello everyone,
I need to write a program that asks the user for 10 numbers and then adds the numbers up. Here's what I've come up with so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main ()
{	
	int a, x, total=0;
	for (x = 1; x <= 10; x++)
	{
		cout << "Enter an integer: ";
		cin >> a;
		total= total + a;
	}
	cout << "The total is " << a << endl;
}


I can't figure out how to get my program to add up the numbers.

Thanks
closed account (o3hC5Di1)
Hi there,

Your program is correct, but you are displaying the wrong variable at the end:

cout << "The total is " << a << endl;

Should be:

cout << "The total is " << total<< endl;

Hope that helps,

All the best,
NwN
Topic archived. No new replies allowed.