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 pennies = 0;
- long double val = 0;
- while(!(days >= 28 && days <= 31)){//ask for days until they ask for a value from [28,31]
- printf("Days in month: ");
- days = get_int();
- }
- while(pennies <= 0){//ask for pennies until they give a positive nonzero number
- printf("Pennies on the first day: ");
- pennies = get_int();
- }
- for(int i = 0; i<days;i++)val += pennies*pow(2,i);//calculate the total amount
- val /= 100;//convert to dollars
- printf("$%.2Lf\n",val);//print the value, only display until the hundreth place
- }
Advertisement
Add Comment
Please, Sign In to add comment