Advertisement
mariammrf_

Problem 3 - Sheet 1

Feb 19th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.     float finalCost, InitialCost;
  5.     int boo, foo, extra=0, number_of_people;
  6.     printf("How many people are going to be staying in the room? ");
  7.     scanf("%d", &number_of_people);
  8.     if (number_of_people>4)
  9.         extra=number_of_people-4;
  10.     number_of_people=number_of_people-extra;
  11.     switch (number_of_people){
  12.         case 2:
  13.         InitialCost=85;
  14.         break;
  15.         case 3:
  16.         InitialCost=90;
  17.         break;
  18.         case 4:
  19.         InitialCost=95;
  20.         break;
  21.         default:
  22.         printf("This number of people is invalid. Please remember that the minimum is 2\n");
  23.         return 0;
  24.     }
  25.     finalCost=InitialCost+(extra*6);
  26.     over60:
  27.     printf("Is the customer over 60? Type 1 for yes, 0 for no\n");
  28.     scanf("%d", &boo);
  29.     if (boo==1)
  30.     finalCost=finalCost*0.85;
  31.     else if (boo==0)
  32.     {
  33.         company:
  34.         printf("Is the customer staying on company business? Type 1 for yes, 0 for no\n");
  35.         scanf("%d", &foo);
  36.         if (foo==1)
  37.         finalCost=finalCost*0.8;
  38.         else if (foo!=0)
  39.         {
  40.             printf("You have entered a wrong number. Try again:\n");
  41.             goto company;
  42.         }
  43.     }
  44.     else
  45.     {
  46.         printf("You have entered a wrong number. Try again:\n");
  47.         goto over60;
  48.     }
  49.     printf("The cost for the room is: %.2f\n", finalCost);
  50.  
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement