0

write a program to display name of the month when the user enters the month as a number

its my homework. plz help me and use switch case

22nd Aug 2016, 3:55 PM
Mayan Pahwa
Mayan Pahwa - avatar
8 Respuestas
+ 3
Well at least you're honest about the homework part.. you really should be educating yourself on this stuff and understanding the concepts, it will definitely benefit you later on in your course. #include <iostream> using namespace std; int main() { int month; cin >> month; if (month < 1 || month > 12) { cout << "Not a valid month!"; return 0; } cout << "Month " << month << " is "; switch (month) { case 1: cout << "January"; break; case 2: cout << "February"; break; case 3: cout << "March"; break; case 4: cout << "April"; break; case 5: cout << "May"; break; case 6: cout << "June"; break; case 7: cout << "July"; break; case 8: cout << "August"; break; case 9: cout << "September"; break; case 10: cout << "October"; break; case 11: cout << "November"; break; case 12: cout << "December"; break; } }
22nd Aug 2016, 4:16 PM
Cohen Creber
Cohen Creber - avatar
+ 3
Single quotations are used with character variables. With integer values, you can do without the single quotations. But you're welcome😁
22nd Aug 2016, 4:34 PM
Cohen Creber
Cohen Creber - avatar
+ 1
actually i got my mistake i had put it like case '1'
22nd Aug 2016, 4:31 PM
Mayan Pahwa
Mayan Pahwa - avatar
+ 1
and thank u
22nd Aug 2016, 4:32 PM
Mayan Pahwa
Mayan Pahwa - avatar
+ 1
Hey guys, why are you doing the homework of others? It defeats the purpose of the homework: OP learns a lot less, if anything.
22nd Aug 2016, 7:16 PM
Stefan
Stefan - avatar
+ 1
Even though it might sound arrogant after my previous message: it can be done via arrays much shorter. Maybe doing it via arrays it regained some of the learning effect? 😉
22nd Aug 2016, 7:19 PM
Stefan
Stefan - avatar
+ 1
I know. I tried to make your homework fulfill its full purpose. :-)
22nd Aug 2016, 11:25 PM
Stefan
Stefan - avatar
0
it was specified using switch case
22nd Aug 2016, 11:20 PM
Mayan Pahwa
Mayan Pahwa - avatar