Monday 14 March 2016

HOTEL TARIFF CALCULATOR


Write a C program to calculate the hotel tariff. The room rent is 20% high during peak seasons [April-June, November-December] . Use Switch statement.

Input Format: 
 The first line of the input contains an integer which corresponds to the number of the month. [ January is 1, Feb is 2 and so on]. The second line of the input consists of a floating point number which corresponds to the room rent per day. The third line of the input consists of an integer which corresponds to the number of days stayed in the hotel.

 Output Format:
 Output consists of a single line which displays the hotel tariff to be payed. Hotel tariff should be displayed correct to 2 decimal places. Refer sample output for format details.

 Sample Input 1: 
 3
 1500
 2

 Sample Output 1: 
 Hotel Tariff: Rs.3000.00

 Sample Input 2: 
 4
 2000
 2
 Sample Output 2: 
 Hotel Tariff: Rs.4800.00

 Sample Input 3: 
 14
 Sample Output 3: 
 Invalid Input

Code:
  #include<stdio.h>
void p(float);
int main()
{
  int month,n;
  float rent,t=0,r=0;
  scanf("%d\n",&month);
  scanf("%f\n",&rent);
  scanf("%d\n",&n);
  t=rent*n;
  r=((rent+(rent*0.2))*n);
  
  switch(month)
  {
    case 1:
      p(t);
      break;
    case 2:
      p(t);
      break;
    case 3:
      p(t);
      break;
    case 4:
      p(r);
      break;
    case 5:
      p(r);
      break;
    case 6:
      p(r);
      break;
    case 7:
      p(t);
      break;
    case 8:
      p(t);
      break;
    case 9:
      p(t);
      break;
    case 10:
      p(t);
      break;
    case 11:
      p(r);
      break;
    case 12:
      p(r);
      break;
    
     
    default: printf("Invalid Input");
    break;
  }
  return 0;
}
  void p(float t)
  {
    printf("Hotel Tariff: Rs.%.2f",t);
  }

5 comments:

  1. getting the following errors in this program :"(
    Compilation Errors -
    1471341096657_tania.rafiqi@gmail.com/Main.c:47:5: warning: label ‘case12’ defined but not used [-Wunused-label]
    Main.c:44:6: warning: label ‘case11’ defined but not used [-Wunused-label]
    Main.c:41:7: warning: label ‘case10’ defined but not used [-Wunused-label]
    Main.c:38:7: warning: label ‘case9’ defined but not used [-Wunused-label]
    Main.c:35:7: warning: label ‘case8’ defined but not used [-Wunused-label]
    Main.c:32:7: warning: label ‘case7’ defined but not used [-Wunused-label]
    Main.c:29:7: warning: label ‘case6’ defined but not used [-Wunused-label]
    Main.c:26:7: warning: label ‘case5’ defined but not used [-Wunused-label]
    Main.c:23:7: warning: label ‘case4’ defined but not used [-Wunused-label]
    Main.c:20:7: warning: label ‘case3’ defined but not used [-Wunused-label]
    Main.c:17:7: warning: label ‘case2’ defined but not used [-Wunused-label]
    Main.c:14:9: warning: label ‘case1’ defined but not used [-Wunused-label]

    PLEASE HELP FIX THE BUG

    ReplyDelete
  2. please use spacebar between case and 1(case 1). You seem to be typing case1 without any space hich gives you error

    ReplyDelete
  3. Please help me out in this explanation for the program

    ReplyDelete