+ 2
How to write gaps in switch operator C++?For example I want to write a program that input year t and output a historical period:
//This is Pascal Case t of -4200000..-3001: writeln('Prehistory'); -3000..476: writeln('Ancient history'); 477..1453: writeln('Middle ages'); 1454..1789: writeln('Modern age'); 1790..2017: writeln('Contemporary age') else begin if (t<-4200000) then writeln('Too old times...'); if (t>2017) then writeln('Future') end; //How to rewrite this in C++???
1 Antwort
+ 5
This is better written using if-else as switch statement need specific cases.
int i;
cin>>i; //input
if (i>-3000&&i <476)
cout <<"Ancient History";
else if (//time period here)
cout <<//period name
.
.
.
.
.
.
else
cout <<"Invalid Input";