Question 1: The bedroom charges of a hotel are based on bedroom category and the
ID: 642882 • Letter: Q
Question
Question 1: The bedroom charges of a hotel are based on bedroom category and the number of days a customer stays at the hotel: Write an interactive C program that displays the following menu: Room Category: 1. Standard Room 2. Double Room 3. Suite Please select your choice (1, 2, or 3) : It then prompts for and reads the bedroom category and the number of days a customer has stayed at the hotel, it finally displays the total charge in Saudi Riyals to be paid. Your program must display appropriate error messages and terminate if the entered category is not valid or if the number of days is zero or negative. Sample program run: Note: The menu must be displayed in a function. Each charge for a bedroom category must be computed in a function. Each of these functions must not contain input or output statements.Explanation / Answer
#include <stdio.h>
#include<stdlib.h>
int days;
int compute1(int days){
int i,charge=0;
for(i=1;i<=days;i++){
if(i<=3){
charge=charge+450;
}
else{
charge=charge+350;
}
}
return charge;
}
int compute2(int days){
int i,charge=0;
for(i=1;i<=days;i++){
if(i<=4){
charge=charge+750;
}
else{
charge=charge+650;
}
}
return charge;
}
int compute3(int days){
int i,charge=0;
for(i=1;i<=days;i++){
if(i<=5){
charge=charge+950;
}
else{
charge=charge+800;
}
}
return charge;
}
int main()
{
int input,stay;
printf( "1. Standard Room " );
printf( "2. Double Room " );
printf( "3. Suite " );
printf( "Selection: " );
scanf( "%d", &input );
printf( "How many days youwant to stay! " );
scanf("%d",&stay);
if(stay<=0){
printf("bad input..exiting..bye");
exit(0);
}
switch ( input ) {
case 1:
printf("Amount to be paid =%d",compute1(stay));
break;
case 2:
printf("Amount to be paid =%d",compute2(stay));
break;
case 3:
printf("Amount to be paid =%d",compute3(stay));
break;
default:
printf( "Bad input, quitting! " );
break;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.