daniel_lawson9999

Daniel Lawson Pennies Program

Sep 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4.  
  5. int main(void){
  6.     int days = 0;
  7.     int pennies = 0;
  8.     long double val = 0;
  9.     while(!(days >= 28 && days <= 31)){//ask for days until they ask for a value from [28,31]
  10.         printf("Days in month: ");
  11.         days = get_int();
  12.  
  13.     }
  14.     while(pennies <= 0){//ask for pennies until they give a positive nonzero number
  15.         printf("Pennies on the first day: ");
  16.         pennies = get_int();
  17.  
  18.     }
  19.     for(int i = 0; i<days;i++)val += pennies*pow(2,i);//calculate the total amount
  20.     val /= 100;//convert to dollars
  21.     printf("$%.2Lf\n",val);//print the value, only display until the hundreth place
  22. }
Advertisement
Add Comment
Please, Sign In to add comment