Advertisement
isabellahaid

Pennies

Oct 23rd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4.  
  5. int main (void)
  6. {
  7. int days = 0;
  8. int fDay = 0;
  9. long double total = 0;
  10.  
  11. printf("Days in month: "); //ask how many days there are in the month
  12. days = get_int();
  13. while(days > 31 || days <28) //in case they do not input a valid number of days
  14. {
  15. printf("Please try again.\nDays in month: ");
  16. days = get_int();
  17. }
  18.  
  19. printf("Pennies on first day: "); //ask how many pennies they are to receive on the first day
  20. fDay = get_int();
  21.  
  22. while(fDay < 0)//in case a negative number is given by the user
  23. {
  24. printf("Please input a positive value. \nPennies on first day: ");
  25. fDay = get_int();
  26. }
  27.  
  28. total = (fDay*(pow(2, days)))/100;
  29. printf("$%.2Lf \n", total);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement