Answer to Question #217716 in C for boi

Question #217716

A student comes to take the admission for the hostel, Provided there are two hostels for girls and boys separately, Allotment has to be done for each student based on type of room i.e, number of sharing. For girls, only three sharing is available but for boys both two and three sharing is available. Given 8,000 for 3 sharing per month and 10,000 for 2 sharing per month.Following are the requirements: 1. Capture the Gender, Type of room, duration of stay(in months) 2. If gender is female/girls, Allotment can be done only with type of room as 3 sharing 3. If gender is male, allotment can be done with type of room as both 2 sharing and also 3 sharing. For two sharing, Amount is 10,000 per month per student and for 3 sharing, Amount is 8000 per month per person. 4. Compute the total Cost( Cost = Amount*duration) for both girls(3 sharing) and boys(2 and 3 sharing) 5. Display the Cost.


1
Expert's answer
2021-07-16T01:05:46-0400
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


#define FEE_2 10000
#define FEE_3 8000


int main() {
    char gender;
    int room_type;
    int duration;
    int amount;
    int cost;


    printf("Enter a gender (Male/Fmaile) - ");
    scanf("%c", &gender);
    gender = tolower(gender);
    if (gender != 'm' && gender != 'f') {
        fprintf(stderr, "Gender must be M or F\n");
        exit(1);
    }

    printf("Enter type of room (2 or 3) - ");
    scanf("%d", &room_type);
    if (gender == 'f' && room_type != 3) {
        fprintf(stderr, "For girls room must be 3 sharing only\n");
        exit(1);
    }
    if (room_type == 2) {
        amount = FEE_2;
    }
    else if (room_type == 3) {
        amount = FEE_3;
    }
    else {
        fprintf(stderr, "For boy room must be 2 or 3 sharing only\n");
    }

    printf("Enter duration (in months) - ");
    scanf("%d", &duration);

    cost = amount*duration;

    printf("The total cost is %d\n", cost);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS