Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that ask the user to enter the gender and time (military format

ID: 3542048 • Letter: C

Question

  

Create a program that ask the user to enter the gender and time (military format 0-23). The program must display a good morning, good afternoon or good night depending the given time. Also the message must include Sr or Ms or nothing if he/she doesn't specify the gender.

From:

6 to 11 --> Good Morning

19 to 23 and 0 - 5 --> Good night

M --> man

F --> woman

example 1:

Enter gender: M

Enter the time: 8

Good morning Sr.!!

Example 2"

Enter gender: F

Enter the time: 14

Good afternoo Ms!!

Example 3:

Gender: U

Enter time: 19

good night!!!

Explanation / Answer

#include <iostream>

using namespace std;


int main(){

char gender;

int time;

cout << "Enter gender: ";

cin >> gender;

cout << "Enter time: ";

cin >> time;

switch(gender){

case 'M':

if(time >= 6 && time <= 11){

cout << "Good morning Sr.!!";

break;

}

if(time >= 12 && time <= 18){

cout << "Good afternoon Sr.!!";

break;

}

if((time >= 19 && time <= 23 )|| (time >= 0 && time <=5)){

cout << "Good night Sr.!!";

break;

}

case 'F':

if(time >= 6 && time <= 11){

cout << "Good morning Ms.!!";

break;

}

if(time >= 12 && time <= 18){

cout << "Good afternoon Ms.!!";

break;

}

if((time >= 19 && time <= 23 )|| (time >= 0 && time <=5)){

cout << "Good night Ms.!!";

break;

}

break;

default:

if(time >= 6 && time <= 11){

cout << "Good morning!!";

break;

}

if(time >= 12 && time <= 18){

cout << "Good afternoon!!";

break;

}

if((time >= 19 && time <= 23 )|| (time >= 0 && time <=5)){

cout << "Good night!!";

break;

}

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote