Using C microsoft visual studios 2013 create a program that
Using C++ (microsoft visual studios 2013) create a program that displays the number of days in a month. Use a 12 element one dimensional array to store the number of days in each month(use 28 for the number of days in febuary). Code the program so that it displays the number of days in the month corresponding to the number entered by the user. For example when the user enters the number 1 the program displays \"There are 31 days in the month of January\". The program should display an error message if the user enters an invalid number. Put a loop in the program so that the user can input multiple months. Use a sentinel of -1 to exit the program.
Solution
#include <iostream>
using namespace std;
int main()
 {
   
 int days[12] = {31,28,31,30,31,30,31,31,30,30,30,31};
 int month;
   
 cout<<\"Enter the month between 1 - 12 (-1 to quit): \";
 cin >> month;
   
 while(month != -1){
 switch(month){
 case 1: cout<<\"There are \"<<days[month-1]<<\" days in the month of January\"<<endl; break;
 case 2: cout<<\"There are \"<<days[month-1]<<\" days in the month of Febuary\"<<endl; break;
 case 3: cout<<\"There are \"<<days[month-1]<<\" days in the month of March\"<<endl; break;
 case 4: cout<<\"There are \"<<days[month-1]<<\" days in the month of April\"<<endl; break;
 case 5: cout<<\"There are \"<<days[month-1]<<\" days in the month of May\"<<endl; break;
 case 6: cout<<\"There are \"<<days[month-1]<<\" days in the month of June\"<<endl; break;
 case 7: cout<<\"There are \"<<days[month-1]<<\" days in the month of July\"<<endl; break;
 case 8: cout<<\"There are \"<<days[month-1]<<\" days in the month of August\"<<endl; break;
 case 9: cout<<\"There are \"<<days[month-1]<<\" days in the month of Setember\"<<endl; break;
 case 10: cout<<\"There are \"<<days[month-1]<<\" days in the month of October\"<<endl; break;
 case 11: cout<<\"There are \"<<days[month-1]<<\" days in the month of November\"<<endl; break;
 case 12: cout<<\"There are \"<<days[month-1]<<\" days in the month of December\"<<endl; break;
 default: cout<<\"Invalid month. \"<<endl;
 }
 cout<<\"Enter the month between 1 - 12 (-1 to quit): \";
 cin >> month;
   
 }
 return 0;
 }
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the month between 1 - 12 (-1 to quit): 6
There are 30 days in the month of June
Enter the month between 1 - 12 (-1 to quit): 9
There are 30 days in the month of Setember
Enter the month between 1 - 12 (-1 to quit): 1
There are 31 days in the month of January
Enter the month between 1 - 12 (-1 to quit): 2
There are 28 days in the month of Febuary
Enter the month between 1 - 12 (-1 to quit): 13
Invalid month.
Enter the month between 1 - 12 (-1 to quit): -1


