Loops

lol
Last edited on
just save the 12 entered numbers in an array or a vector.
In my Comp Sci, we haven't gotten to arrays or vectors yet..only through Loops.
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
32
33
34
int main() {
    double average(0), max(0), min(9000);
    int maxnum, minnum;
    for(int month = 0; month < 12; ++month) {
        double temp;
        std::cin >> temp;
        average += temp;
        if (max < temp) {
            max = temp;
            maxnum = month;
        }
        if (min > temp) {
            min = temp;
            minnum = month;
        }
    }
    average /= 12;

    std::string month;
    switch(maxnum) {
        case 0: month = "January"; break;
        case 1: month = "February"; break;
        /*...*/
    }
    std::cout << "max rainfall was in " << month << " and equals " << max <<
                 "inches" << std::endl;

    switch(minnum) {
        case 0: month = "January"; break;
        case 1: month = "February"; break;
        /*...*/
    }
    std::cout//...
}



Example without using arrays. I would use an array to store month names in it though.
Topic archived. No new replies allowed.