Problem 3 20 Points Write a program which asks a user to ent

Problem 3 (20 Points) Write a program, which asks a user to enter a 3-digit apartment number of a 3-story building, and responds which floor the room is located based on the first number. For example, Apt. 105 is located on the first floor, and Apt. 211 is located on the second floor. If the user enters an apartment numbers that does not exist, your program would return an error message. Example session are shown below. Page 2 of 3 >> Apt Please enter an apartment number: 213 The apartment is on the second floor. >> >> Apt Please enter an apartment number: -5 Sorry, that apartment does not exit. >> Run four different values, so that your command-window session will show cases corresponding to the first floor, second floor, third floor, or “none of above.”

(show Script Please)

Solution

/*Write a program, which asks a user to enter a 3-digit apartment number of a 3-story building,
and responds which floor the room is located based on the first number. */

#include <iostream>
using namespace std;

int main()
{
int apt_num;
int floor;
cout <<\"Please enter an apartment number:\";
cin>>apt_num;

if( (apt_num>=100) && (apt_num <=999))
{
/* here floor is int varaible that show first number of three digit apartment */
floor=apt_num/100;
/* using switch loop find apartment floor */
switch(floor)
{
case 1:cout<<\"The apartment is on the First floor.\"<<endl;
break;
case 2: cout<<\"The apartment is on the Second floor.\"<<endl;
break;
case 3:cout<<\"The apartment is on the Third floor.\"<<endl;
break;
default: cout<<\"In 3-story building only three floor. Run four different values between 100 to 300\"<<endl;
}

}
else
{
cout<<\"Sorry, that apartment does not exit. Run four different values\"<<endl<<endl;

}
return 0;
} // End of main

-------------------------------------------------

output:-

Please enter an apartment number:175
The apartment is on the First floor.

Please enter an apartment number:234
The apartment is on the Second floor.

Please enter an apartment number:388
The apartment is on the Third floor.

Please enter an apartment number:75
Sorry, that apartment does not exit. Run four different values

Please enter an apartment number:777
In 3-story building only three floor. Run four different values between 100 to 300

======================================================================

I wrote this program in C++, if you need in other programming langaue like C and Java then comment me i will send you on other language

If you have any query, please feel free to ask

Thanks a lot

Problem 3 (20 Points) Write a program, which asks a user to enter a 3-digit apartment number of a 3-story building, and responds which floor the room is located
Problem 3 (20 Points) Write a program, which asks a user to enter a 3-digit apartment number of a 3-story building, and responds which floor the room is located

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site