Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <math.h>
- int main (void)
- {
- int days = 0;
- int fDay = 0;
- long double total = 0;
- printf("Days in month: "); //ask how many days there are in the month
- days = get_int();
- while(days > 31 || days <28) //in case they do not input a valid number of days
- {
- printf("Please try again.\nDays in month: ");
- days = get_int();
- }
- printf("Pennies on first day: "); //ask how many pennies they are to receive on the first day
- fDay = get_int();
- while(fDay < 0)//in case a negative number is given by the user
- {
- printf("Please input a positive value. \nPennies on first day: ");
- fDay = get_int();
- }
- total = (fDay*(pow(2, days)))/100;
- printf("$%.2Lf \n", total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement