[Solved] Beginning C++: using if else, n–, number [closed]


  1. there is a spelling mistake in your code of sum_positive in line (cout << sum_postive << endl;) – you have written sum_postive but you declared sum_positive.

  2. you are running a loop and taking input in the same variable number, so it will overwrite all the inputs and will store only the last value in variable number which user entered. So your sum will always be equal to the last value user entered.

For this you need to use an array.
Example:

int number[10], n=10, sum_positive=0;
do{
    cout<<"e`enter code here`nter number:";
    cin>>number[n];
    n--;
}while(n>0);

now for sum also you need to use an loop.

If you do not know about an array, study about it how to use it.

solved Beginning C++: using if else, n–, number [closed]