string in arrays

Im doing a question from a book
4. You sell the book C++ for Fools. Write a program that has you enter a year’s worth of monthly sales (in terms of number of books, not of money). The program should use a loop to prompt you by month, using an array of char * (or an array of string objects, if
you prefer) 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 contents and report the total sales
for the year.

im getting
[Error] variable-sized object 'months' may not be initialized
my array is setup like one of the book examples no idea why its giving me an eror
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
#include <iostream>

int main() 
{
	using namespace std;
	
	
	int numberofmonth = 12;
	int booksold [numberofmonth];
	int counter = 0;
	char months[numberofmonth] = //Im getting error here
		{
			"Jan", "Feb", "March", "April", "May", "June",
			 "July", "Aug", "Sep", "Oct", "Nov", "Dec"
		};
	
	do 
	{
	cout << months[counter];
	cout << "\Enter number of sales: ";
	cin >> booksold[counter];
	++counter;
	}
	while(counter != numberofmonth);
	
	return 0;
}  
line 11 - char month[12] is a character array that can store up to 12 single characters.

If you #include <string> , you can make an array of strings.

string months[] = {"Jan", "Feb", "March", "April", "May", "June","July", "Aug", "Sep", "Oct", "Nov", "Dec"};


line 20 - is that supposed to be a newline \n before Enter?
yeah suppose to \n
thanks string made it work
you could do like wildblue said or get rid of the " " in the char array and turn them into ' '.
This is because quotations mark are used to represent string literals but it's up for you to decide cheers.
Topic archived. No new replies allowed.