I wrote a basic c program with if and else if statements to calculate a hotel bill but I keep getting the same error.
long.c:97:8: error: expected identifier or ‘(’ before ‘else’
else if(room == 3)
^~~~
long.c:133:2: error: expected identifier or ‘(’ before ‘else’
else
^~~~
long.c:136:9: error: expected identifier or ‘(’ before ‘return’
return 0;
^~~~~~
long.c:137:1: error: expected identifier or ‘(’ before ‘}’ token
The program has been attached,
Code:
#include<stdio.h>
int main(void)
{
//declaring variables
float total;
char card, accbasis;
int room, days;
//printing statements to get inputs
printf("Enter type of room:\n");
scanf("%d", &room);
printf("Enter accomodation basis:\n");
scanf("%c ", &accbasis);
printf("Enter card type:\n");
scanf("%c ", &card);
printf("Enter number of days:\n");
scanf("%d", &days);
//conditions
if(room == 1)
{
if(accbasis == 'F')
{
if(card == 'G')
total = 25555.00 * days - 25555.00 * 12.5;
else if(card == 'S')
total = 25555.00 * days - 25555.00 * 11.5;
else if(card =='B')
total = 25555.00 * days - 25555.00 * 9.5;
else
{
printf("Invalid card type.");
printf("The total is %.2f", total);
}
}
else if(accbasis == 'H')
{
if(card == 'G')
total = 17250.00 * days - 17250.00 * 12.5;
else if(card == 'S')
total = 17250.00 * days - 17250.00 * 11.5;
else if(card == 'B')
total = 17250.00 * days - 17250.00 * 9.5;
else
{
printf("Invalid card type.");
printf("The total is %.2f" , total);
}
}
else
printf("Invalid accomodation basis.");
}
else if(room == 2)
{
if(accbasis == 'F')
{
if(card == 'G')
total = 17500.00 * days - 17500.00 * 12.5;
else if(card == 'S')
total = 17500.00 * days - 17500.00 * 11.5;
else if(card == 'B')
total = 17500.00 * days - 17500.00 * 9.5;
else
{
printf("Invalid card type.");
printf("The total is %.2f", total);
}
}
}
else if(accbasis == 'H')
{ if(card == 'G')
total = 12250.00 * days - 12250.00 * 12.5;
else if(card == 'S')
total = 12250.00 * days - 12250.00 * 11.5;
else if(card == 'B')
total = 12250.00 * days - 12250.00 * 9.5;
else
{
printf("Invalid card type");
printf("The total is %.2f", total);
}
}
else
printf("Invalid accomodation basis");
}
else if(room == 3)
{
if(accbasis == 'F')
{
if(card == 'G')
total = 9000.00 * days - 9000.00 * 12.5;
else if(card == 'S')
total = 9000.00 * days - 9000.00 * 11.5;
else if(card == 'B')
total = 9000.00 * days - 9000.00 * 9.5;
else
{
printf("Invalid card type.");
printf("The total is %.2f", total);
}
}
else if(accbasis == 'H')
{
if(card == 'G')
total = 7250.00 * days - 7250.00 * 12.5;
else if(card =='S')
total = 7250.00 * days - 7250.00 * 11.5;
else if(card == 'B')
total = 7250.00 * days - 7250.00 * 9.5;
else
{
printf("Invalid card type.");
printf("The total is %.2f", total);
}
}
}
else
printf("Invalid room type");
return 0;
}