loop to find the sum

I want to ask the user to input a number . After that ,the programme ask if he want to input a number again .i know how to make the loop. However, i don"t understand how to calaculate the sum of those number as i don"t know how many number the user will input

Another question is how can i convert lowercase to uppercase

Thx a lot
I had the exact same homework assignment like this, my solution was

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main()
{
    double num[10], sum=0;
    int i=0;
    char option;
    while (option!='n'){
        cin >> num[i];
        cin >> option;
        sum=sum+num[i];
        i++;
        }
    cout << sum << endl;
    
    system ("pause");
    return 0;
}


its not very good, but it works :)
cin >> num[i];
enters a number into the array
cin >> option;
if user enters "n" it will exit the loop
sum=sum+num[i];
sums up the array
Last edited on
@youichi

I think you can do it like that:

1
2
3
4
while (cin >> number) { //if input is a number,save it. if not, quit the loop.
    sum += number;
    ++times;
}


You can use C function "toup(c)" to convert a char to uppercase.
Then you can write a loop to convert a string to uppercase.
Last edited on
Topic archived. No new replies allowed.