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.
#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;
}
Comments
Leave a comment