Problem adding doubles

Hi,

I have the following array which is adding the numbers entered by the user the issue I'm having is that it only works if the user enter whole numbers, but if the user enters decimals like .2, .3 etc it doesn't add the numbers.

Any idea whats wrong?

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
int main()// start main
{
    const int MONTHS = 4;

    double monthArrey[MONTHS];
    
    int total = 0;
    
    cout<< "Enter rainfall for each month: " << endl;
    cout<< endl;
    for(int i = 0; i < MONTHS; i++ )
    {       
        cin >> monthArrey[i];
    }
    
    
    cout<< "Rainfall numbers: " << endl;
    int j =0;
    while (j<MONTHS) {
        total += monthArrey[j];
        j++;
        
    }
     cout << "Total: "<< total <<" ";    
    
    return 0;
    
} // end main 


Thanks a lot
Last edited on
Make total a double.
Shame on me I should know that, Thanks a lot for your help!
Topic archived. No new replies allowed.