Sum of first n numbers

Trying to get the sum of first n numbers. If I enter in 3, the sum I get is 11. Anyone tell me whats wrong with equation?

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
  int sum;
	sum=0;
	int counter;
	int number1;
	number1=1;
	counter=1;
	//Declare variable for which user enters the first n numbers to find their sum
	int n;

	//Tell user for first n numbers

	cout<<"First N Numbers: ";
	cin>>n;

	while (counter>=0 && counter<=n)
	 
	{
		sum=number1+counter;
		number1=counter;
		sum=sum +number1+counter;
		counter++;
	
	}

	cout<<"\n\n\tSum of first n number is: " <<sum;
	_getch();
Why are you setting the value of sum twice?
Why are you including counter in your calculations?
Topic archived. No new replies allowed.