fork download
  1. #include <stdio.h>
  2. main()
  3. {
  4. int kids;
  5. int * pKids;
  6. float price;
  7. float * pPrice;
  8. char code;
  9. char * pCode;
  10. price = 17.50;
  11. pPrice = &price;
  12. printf("\nHow many kids are you taking to the water park? ");
  13. scanf(" %d", &kids);
  14. pKids = &kids;
  15. printf("\nDo you have a discount ticket for the park?");
  16. printf("\nEnter E for Employee Discount, S for Sav-More ");
  17. printf("Discount, or N for No Discount: ");
  18. scanf(" %c", &code);
  19. pCode = &code;
  20. printf("\nFirst let's do it with the pointers:\n");
  21. printf("You've got %d kids...\n", *pKids);
  22. switch (*pCode)
  23. {
  24. case ('E') :
  25. printf("The employee discount saves you 25%% on the ");
  26. printf("$%.2f price", *pPrice);
  27. printf("\nTotal ticket cost: $%.2f", (price*.75 * *pKids));
  28. break;
  29. case ('S') :
  30. printf("The Sav-more discount saves you 15%% on the ");
  31. printf("$%.2f price", *pPrice);
  32. printf("\nTotal ticket cost: $%.2f", (*pPrice * .85 * *pKids));
  33. break;
  34. default : // Either entered N for No Discount or an invalid letter
  35. printf("You will be paying full price of ");
  36. printf("$%.2f for your tickets", *pPrice);
  37. return (0);
  38. }
  39. }
  40.  
Success #stdin #stdout 0s 2116KB
stdin
Standard input is empty
stdout
How many kids are you taking to the water park? 
Do you have a discount ticket for the park?
Enter E for Employee Discount, S for Sav-More Discount, or N for No Discount: 
First let's do it with the pointers:
You've got -1217241523 kids...
You will be paying full price of $17.50 for your tickets