English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
1

#include
#include

using std::cout;
using std::cin;
using std::endl;
using std ::string;

int main ()
{

string numberMonth[12]= {"Janurary","Feburary","March","April","May","June","July","August","September","October","November","December"};
string flowerOfmonth [12]={" "};
flowerOfmonth[0]="Carnation";
flowerOfmonth[1]="Violet";
flowerOfmonth[2]="Daffodile";
flowerOfmonth[3]="Daisy";
flowerOfmonth[4]="Lily-of-the-Valley";
flowerOfmonth[5]="Rose";
flowerOfmonth[6]="Water Lily";
flowerOfmonth[7]="Gladiolus";
flowerOfmonth[8]="Aster";
flowerOfmonth[9]="Cosmos";
flowerOfmonth[10]="Chrysanthemum";
flowerOfmonth[11]="Narcissus";

//get number of month
cout << "Enter month (1-12) :" << endl;
cin >>numberMonth;
if (month >= 1 && month <= 12)
cout << flowerOfmonth[numberMonth - 1] << endl;
//else
cout << "Invalid month" << endl;
//end if
//end display salary

return 0;
} //end of main function


why cant i get this to work..thanks

2007-10-28 11:32:43 · 2 answers · asked by grimlok2k6 1 in Computers & Internet Programming & Design

2 answers

You are expecting users to enter NUMERIC representation of the months. The wording of the months is NEVER used. So, numberMonths array definition is not needed.

Define numberMonths as an INTEGER.

Look what exactly you are doing with the numberMonth variable! It's an index for an array. Yet, you defined it as string.

2007-10-28 11:44:43 · answer #1 · answered by tkquestion 7 · 1 0

try to chaneg this line
string flowerOfmonth [12]={" "};
to
string flowerOfmonth [12];
OR
initialize the second array as you have done with the first one
string flowerOfmonth = {"Carnation", "Violet", "Daffodile", ... }

2007-10-28 18:47:03 · answer #2 · answered by Me 4 · 0 0

fedest.com, questions and answers