#include %26lt;string%26gt;
#include %26lt;iostream%26gt;
using std::cout;
using std::cin;
using std::endl;
using std ::string;
int main ()
{
string numberMonth[12]= {%26quot;Janurary%26quot;,%26quot;Feburary%26quot;,%26quot;March%26quot;,%26quot;April%26quot;,%26quot;...
string flowerOfmonth [12]={%26quot; %26quot;};
flowerOfmonth[0]=%26quot;Carnation%26quot;;
flowerOfmonth[1]=%26quot;Violet%26quot;;
flowerOfmonth[2]=%26quot;Daffodile%26quot;;
flowerOfmonth[3]=%26quot;Daisy%26quot;;
flowerOfmonth[4]=%26quot;Lily-of-the-Valley%26quot;;
flowerOfmonth[5]=%26quot;Rose%26quot;;
flowerOfmonth[6]=%26quot;Water Lily%26quot;;
flowerOfmonth[7]=%26quot;Gladiolus%26quot;;
flowerOfmonth[8]=%26quot;Aster%26quot;;
flowerOfmonth[9]=%26quot;Cosmos%26quot;;
flowerOfmonth[10]=%26quot;Chrysanthemum%26quot;;
flowerOfmonth[11]=%26quot;Narcissus%26quot;;
//get number of month
cout %26lt;%26lt; %26quot;Enter month (1-12) :%26quot; %26lt;%26lt; endl;
cin %26gt;%26gt;numberMonth;
if (month %26gt;= 1 %26amp;%26amp; month %26lt;= 12)
cout %26lt;%26lt; flowerOfmonth[numberMonth - 1] %26lt;%26lt; endl;
//else
cout %26lt;%26lt; %26quot;Invalid month%26quot; %26lt;%26lt; endl;
//end if
//end display salary
return 0;
} //end of main function
why cant i get this to work..thanks
C++ array?
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%26#039;s an index for an array. Yet, you defined it as string.
Reply:try to chaneg this line
string flowerOfmonth [12]={%26quot; %26quot;};
to
string flowerOfmonth [12];
OR
initialize the second array as you have done with the first one
string flowerOfmonth = {%26quot;Carnation%26quot;, %26quot;Violet%26quot;, %26quot;Daffodile%26quot;, ... }
flower
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment