char, loop, array?

I need help with figuring out this code! I will be forever grateful.

Problem: I sell c++ for fools. I need to write a program that tells the user to enter a year's worth of monthly sales( in terms of books, not money.) The program should use a loop to prompt the user by month, using an array of char initialized to the month strings and storing the input data in an array of int. Then, the program should find the sum of the array content and report the total sales for the year.

This is all a completely different language to me and any help would be amazing!
You are going to want an container (array) that stores each month, and the amount of books against the month. Am I correct? If so, you will need something like below.

I have given you the basic code using a map. It looks quite complicated at first but once you understand it, it's an easy way to store values against strings (or other values).

This code should compile and run as is.

peace.
Z.

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
#include <iostream>
#include <string>
#include <map> // STL Map

using namespace std;

int main() {
 map<string, int> mSales;

 mSales["May"]    = 0;
 mSales["June"]   = 0;

 map<string, int>::iterator vPtr = mSales.begin();
 while (vPtr != mSales.end()) {
   cout << "Enter Sales For " << (*vPtr).first << ": ";
   
   int Sales = 0;
   cin >> Sales;
   
   mSales[ (*vPtr).first ] = Sales;
   
   vPtr++;
 }
 
 // Display
 vPtr = mSales.begin();
 while (vPtr != mSales.end()) {
   cout << "Month " << (*vPtr).first << " had " << (*vPtr).second << " sales" << endl;
   vPtr++;
 }
 
 return 0;
}
the code became completely scrambled when i entered it into the program.
along with 94 warnings.

help?
Topic archived. No new replies allowed.