I need help!!!

Assignment:

1. Create a vector (snow) that will hold integers which represent snowfall amounts for several months.

2. Place your name on the screen as the master snowfall recorder:
“Master Snowfall Recorder: John Paul Jones”

3. Ask the user how many months they would like to record. (input 5 when the program runs)

4. Create a loop that will ask for the “Snowfall amount for month # 1: “, etc

5. Fill the vector with the amounts input by the user.

6. Keep track of the grand total of the amounts in the fill loop.

7. In a separate loop, print the snowfall amounts back out on the screen, following the same format as in step 4.

8. Label and report the grand total after all input.
Grand total: .. inches of snow

9. Using the size function, label and report the number of months recorded.
There are ... months recorded.

10. Write the code that will remove the last snowfall amount from the vector.

11. Label and report the number of months recorded.
There are now … months recorded.

12. Clear all elements from the vector.

13. Label and report the number of months recorded.
After clearing all data, there are …months recorded

14. Give some clever goodbye message.
Last edited on
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
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;

int main() {
    
    vector<int> snow;                    
    int monthRecord;
    int index;                            
    int snowAmount;

    
    cout << "\t\t\t\tMaster Snowfall Recorder: John Doe" << endl << endl;
    
    // Get the number of months 
    cout << "How many months would you like to record?: ";
    cin >> monthRecord;
    
    
    
    // Snowfall data.
    cout << "\nEnter snowfall for " << monthRecord;
    cout << " months.\n";
    for (index = 0; index < monthRecord; index++)
    {
        cout << "Snowfall amount for month #" << (index + 1);
        cout << ": "; 
        cin >> snowAmount;
        snow.push_back(snowAmount);
    }
    
    
    // Display snowfall amount for each month.
    cout << "\nSnowfall Amounts \n";
    cout << fixed << showpoint << setprecision(2);
    for (index = 0; index < monthRecord; index++)
    {
        cout << "\nMonth #" << (index + 1);
        cout << ": " << snowAmount << endl;
    }
    
    
    system("pause");
    return 0;
}
Last edited on
I do not understand #7 and #8 of the assignment.
For #7 you are pretty close.
Instead of snowAmount you need to take the values from the vector
#8 "grand total" means "sum", i.e. all snow together, does it not?


#9 wants you to use certain function. You should actually use that function on line 37 too.
@Thomas1965 where would I fix this? Which line? Because when I run the program, the number I enter for the last month , that same number (snow amount) displays for all months.
same number (snow amount) displays for all months

Of course. You do repeat cout << snowAmount monthRecord times and showAmount does not change during that loop. Displaying same value displays same value.

What do you do on line 30? What is the snow? Why do you have it? What does it have after line 31?
On line 40 it should be snow[index]
Last edited on
Thanks guys it is working now
Topic archived. No new replies allowed.