+ 3

How do i create an array and use it to display specific data?

So i've been working on a code that would show top5 international news headlines of each month of this year. So i created an array as of following : String news [ ]= { 1, 2, 3, 4, 5} ; And another string like this String month; What i wanted to do is, use "if loop" for this. As the user would write january, the data would be stored to string month with this code cin>> month; , and if month==news [0] then it would show the headlines from that month which i'd write like this : cout<< news [0]<<endl; But the error occurs at the very beginning of the string news[ ], with 5 lines of saying "error: '1'/ '2'/ '3' was not declared in this scope" What did i do wrong, and how can i fix it. And if there is any other way to write this program with c++, i'd be glad to get suggestions as well.

7th Jul 2019, 7:23 AM
Sami Rashid
Sami Rashid - avatar
4 Réponses
+ 3
I fixed it boys, didn't put the elements of the string inside " " thats why the error ocurred.
7th Jul 2019, 7:40 AM
Sami Rashid
Sami Rashid - avatar
+ 2
@~swim~ yes true...I agree with u... But we can use if condition like loop by using.....goto statement
5th Aug 2019, 5:43 PM
U Hariharan
U Hariharan - avatar