this program should display the number of days in a month, but it's not working why? this is my code:
#include %26lt;iostream%26gt;
using std::cout;
using std::cin;
using std::endl;
int main ( )
{
//declare varibles
int days[12] = {31, 28, 31, 30, 31, 30, 31, 30, 30, 31, 30, 31};
int monthNumber =0;
//get input from user
cout %26lt;%26lt; "Enter the month's number: " %26lt;%26lt; endl;
cin %26gt;%26gt; monthNumber;
while (monthNumber =! -1)
if (monthNumber %26gt;= 1 %26amp;%26amp; monthNumber %26lt;= 12)
cout %26lt;%26lt; "Number of Days: "%26lt;%26lt; days [monthNumber - 1];
else
cout %26lt;%26lt; "Invalid Input" %26lt;%26lt; endl;
//end if
cout %26lt;%26lt; "Enter the month's number: " %26lt;%26lt; endl;
cin %26gt;%26gt; monthNumber;
return 0;
} //end while
Please help me with my C++ program! please!!?
while (monthNumber =! -1)
That should be:
while(monthNumber != -1)
You are also not putting the while stuff into a curly bracket. So It doesn't repeat the whole block of code.
while(monthNumber != -1)
{
if (monthNumber %26gt;= 1 %26amp;%26amp; monthNumber %26lt;= 12)
cout %26lt;%26lt; "Number of Days: "%26lt;%26lt; days [monthNumber - 1] %26lt;%26lt; endl;
else
cout %26lt;%26lt; "Invalid Input" %26lt;%26lt; endl;
//end if
cout %26lt;%26lt; "Enter the month's number: " %26lt;%26lt; endl;
cin %26gt;%26gt; monthNumber;
}
Reply:try taking the return 0; from outside the while. that is making you exit the program after you insert a number for the second time without seeing the answer.
And can you tell us what is not working? what happens?
garden state
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment