ssoni

hello2.c

Dec 2nd, 2021 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. int main(void) {
  5.  
  6. //Declare variables
  7. int age = 0;
  8. float wage;
  9. int hours;
  10. string fName;
  11. float totalPay;
  12.  
  13. fName = get_string("What's your name?\n");
  14.  
  15. while (age <= 0 || age > 105) {
  16. age = get_int("How old are you?\n");
  17. }
  18.  
  19. if (age < 21) {
  20. printf("Milk for you\n");
  21. }
  22. else {
  23. printf("Wine for you\n");
  24. }
  25.  
  26. if (age < 18) {
  27. printf("Can't vote\n");
  28. }
  29. else if (age < 65) {
  30. printf("Go to work and vote at night\n");
  31. }
  32. else {
  33. printf("Let's golf and vote after lunch\n");
  34. }
  35.  
  36. if (age > 18) {
  37. wage = get_float("How much do you earn per hour?\n");
  38. hours = get_int("How many hours did you work this week?\n");
  39. totalPay = wage * hours;
  40. printf("Hello, %s. You worked %i hours at $%.2f an hour.\n",fName, hours, wage);
  41. printf("You earned $%.2f this week.\n", totalPay);
  42. }
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
Add Comment
Please, Sign In to add comment