summing up array with negative number

Hello volks, I'm trying to write an array that add 10 integers from user's input. That will include negative numbers. My program seems fine with different test, but when I add 9 ones, and one -1, the result is 8, but the answer supposed to be 9.
(What I tested to Enter 1 1 1 1 1 1 1 1 1 -1, result =8). Please point out my error! Thank you

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
#include <iostream>
using namespace std; 
int main(){
	
	int array1[9];
	int sum=0;
	int count=0;
	
	
	cout <<"Enter 10 interger numbers: " <<endl;
	
	for(int i=0; i<=9; i++){
		cin>> array1[i];
		sum+= array1[i];
	}
	
	cout <<"The sum of the interger numbers is: " << sum <<endl;
	
	for (int i=0; i<=9; i++){
		if(array1[i]<0){
			count ++;
		}
	}
	cout <<"You've entered: " <<count << " of negative number(s)";
	
	
	
	
	
	return 0;
}
Last edited on
when I add 9 ones, and one -1, the result is 8, but the answer supposed to be 9.

i haven't checked your program but the result of 9*1 - (1) should indeed be 8, not 9
OMG, that's right I did a stupid calculation, LOL, thank you!
Topic archived. No new replies allowed.