Write a C program that reads in an integer number from the keyboard. (IN THIS PROGRAM YOU MUST NOT USE THE “IF” STATEMENT) • If the number is less than 1 or greater then 24 exit. • If the number is between 7 and 12 print to the screen: “morning”. • If the number is between 13 and 17 print to the screen: “afternoon”. • If the number is between 18 and 20 print to the screen: “evening”. • In the rest of the cases print out: “night or dawn”.
void main() { int a; cin>>a; switch(a<1 || a>24) { case 1: exit(0); } switch(a>7 || a<12) { case 1: cout<<"morning"; exit(0); } switch(a>13 || a<17) { case 1: cout<<"afternoon"; exit(0); } switch(a>18 || a<20) { case 1: cout<<"evening"; exit(0); } cout<<"night or dawn"; }
Join our real-time social learning platform and learn together with your friends!