1. validating a magic date

H! I am making a program which takes date month and year as input and validates that whether the given date is a magic date or not the criteria for magic date is
1)if month*date is one digit number and it is equal to last digit of the year it is a magic date for example 02,03,2006.
2)if month*date is a two digit number and it is equal to last two digits of the year it is a magic date for example 09,02,2018
3)if month*date is a three digit number and it is equal to last three digits of the year it is a magic date for example 30,10,2300.

now programs requirements are that the input year should be of four digits and this program should be made by using switch statement.

problem: i have made this program using if else but i dont understand how can i make it using switch statement.

(PROGRAM USING IF-ELSE):
Code:
#include<iostream>
using namespace std;
int main()
{
int dd,mm,yyyy,a,b,c,d;
cout<<"enter date ";
cin>>dd;
if(dd<=0||dd>31)
cout<<"invalid date";
else{
cout<<"enter month ";
cin>>mm;}
if(mm<=0||mm>12)
cout<<"invalid month";
else{
cout<<"enter year ";
cin>>yyyy;}
if(yyyy<1000||yyyy>9999)
cout<<"invlaid year range ";
if(yyyy%10==(mm*dd))
cout<<"special date"<<endl;
else if(yyyy%100==(mm*dd))
cout<<"special date"<<endl;
else if(yyyy%1000==(mm*dd))
cout<<"special date"<<endl;
else
cout<<"not a special date"<<endl;
system("pause");
return 0;
} 2. switch / case work well when
- one side of your if expressions are constants
- those constants are close together.

But your if's are variable on both sides, and the range is 1 to 372 (31*12)

I suppose you could contrive something with
Code:
int magic = mm * dd;
string s = std::to_string(magic);
switch ( s.length() ) {
case 1:
} Popular pages Recent additions c++, code needed, help and support, modification, switch case 