summation

Hello, i am beginner in C++. i want to add 10 different values as input and make summation of that. Can anyone help me to do this?



#include<iostream>
using namespace std;

int main()
{
const int size = 10;
int number[size];
cout << "enter :" << endl;
cin >> number[size];
int total;
for(int count=0; count < size; count++)

total += number[count] ;

cout << "total = " << total << endl;

system("pause");
return 0;
}
You missed the input part of the process. Sure you want 10 numbers but telling the program cin >> number[size]; doesn't mean it will read 10 numbers into the array. In that line of code, you simply told the program to read 1 number into the very end of the array which is not a valid position anyways since valid array indices are 0 -> size - 1.

Just like you did for tallying the numbers, you have to use the same method to read in the numbers. So instead of doing total += number[count] ;, you replace that line with cin >> number[count];
Topic archived. No new replies allowed.