Write a program that asks the user to enter any date in the format specified above (month/day/2-digit-year). (It is very important that the input is in the correct format, typed all at once, all on one line, by the user. See the hints below.) The program should then determine whether the month times the day is equal to the year. If so, it should display a message saying the date is magic. Otherwise it should display a message saying the date is not magic.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Write a
Do not use any string variables in this assignment.
Hints: Read the three data into three separate int variables. Even though the user will be typing only one line of input, you will be using the extraction operator multiple times to read that input. I strongly suggest that you review lesson 2.9 before starting on this assignment.
To make your job easier, we will specify that it is still a valid date if the user uses a different punctuation character instead of a slash. For example, 6%10;60 would be a valid date (and a magic date).
Here are two sample runs (user's input shown in bold):
Enter a date in the format month/day/2-digit-year: 6/10/60 That is a magic date! Enter a date in the format month/day/2-digit-year: 6/10/61 That is not a magic date! C++
Trending now
This is a popular solution!
Step by step
Solved in 2 steps