This program was coded to complete one of my university lab-sheets. I don't know how to modify the scanf()
statement to correct this error.
It seems there is an error with the switch-case too. This is my code.
#include<stdio.h>
//Function main
int main (void)
{
char roomType,payingMethod,cont;
int noOfRooms=0,noOfNights=0;
float discount=0,amount=0;
while(cont!='n'||cont!='N')
{
printf("\n(D-Deluxe|S-Superior Deluxe|C-Club Suits|E-Executive Suits|P-Presidential Suits)\nENTER THE ROOM TYPE:");
scanf("%c%*c",&roomType);
if(roomType!='D' || roomType!='S' || roomType!='E' || roomType!='C' || roomType!='P')
{
printf("Invalid Room Type!\n");
return 0;
}
printf("\nENTER THE NUMBER OF ROOMS:");
scanf("%d",&noOfRooms);
printf("\nNUMBER OF NIGHTS:");
scanf("%d",&noOfNights);
printf("\nPAYING METHOD (M-cash|C-credit card):");
scanf("%c%*c",&payingMethod);
if(payingMethod=='c'||payingMethod=='C')
discount=0.9;
else
discount=1.0;
switch(roomType)
{
case 'D':
amount=31000*noOfRooms*noOfNights*discount;
break;
case 'S':
amount=35000*noOfRooms*noOfNights*discount;
break;
case 'C':
case 'c':
amount=50000*noOfRooms*noOfNights*discount;
break;
case 'E':
case 'e':
amount=75000*noOfRooms*noOfNights*discount;
break;
case 'P':
case 'p':
amount=100000*noOfRooms*noOfNights*discount;
break;
}
printf("\nTotal amount payable: %f\n",amount);
printf("\nDO you want to continue(y/n):");
scanf("%*c%c",&cont);
printf("__________________________________________________________");
}
}//End function main