Hellp all! Hoping to make new friends here:
Anyways,
I am new to C++ and to programming. I just started reading the book "Problem Solving with C++, 7th ed." by Walter Savitch. I am already having problems. One of the programs I am trying to figure out (not in the book) is how to figure for how many days a month has. The problem I am having is with leap year (Feb). Here is what I have so far:
#include <iostream>
using namespace std;
int main()
{
int Month, Year;
cout << "Enter a number matching the month \n";
cout << "of the year, then press return\n";
cin >> Month;
cout << " \n";
switch (Month)
{
case 1:
cout << "There are 31 days in January.\n";
break;
case 3:
cout << "There are 31 days in March.\n";
break;
case 4:
cout << "There are 30 days in April.\n";
break;
case 5:
cout << "There are 31 days in May.\n";
break;
case 6:
cout << "There are 30 days in June.\n";
break;
case 7:
cout << "There are 31 days in July.\n";
break;
case 8:
cout << "There are 31 days in August.\n";
break;
case 9:
cout << "There are 30 days in September.\n";
break;
case 10:
cout << "There are 31 days in October.\n";
break;
case 11:
cout << "There are 30 days in November.\n";
break;
case 12:
cout << "There are 31 days in December.\n";
break;
case 2:
cout << "Please enter the year.\n";
cin >> Year;
break;
if (Year % 4 == 0)
cout << "February has 29 days. This is a Leap Year\n";
else
cout << "February has 28 days. \n";
break;
default:
cout << "Please select from 1-12. There are only 12 months in the year. Thank you.\n";
}
cout << " \n";
char letter;
cout << "Enter a letter to end the program:\n";
cin >> letter;
cout << "Goodbye.\n";
return 0;
}