/ Published in: C
see the change
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <cs50.h> #include <stdio.h> #include <math.h> int main(void) { // ichangeD is equal to the change in dollars float ichangeD; //ichangeC is equal to the change in cents int ichangeC; do { // ask for user the change and covert it to cents ichangeD = GetFloat(); ichangeC = round(ichangeD * 100); } while(ichangeD < 0); // declare variables of different possible monetary values int DaCount = 0; int DaDCount = 0; int ldollars = 0; int gdollars = 0; int hdollars = 0; int jdollars = 0; int quarters = 0; int dimes = 0; int nickles = 0; int pennies = 0; while(ichangeC % 2000 != ichangeC) { jdollars++; DaDCount++; ichangeC = ichangeC - 2000; } // since remainder of something less that a certain number is that number that you // trying to divide, use a while loop to do this until something happens // then move on to the next monetary value while keeping track of count of money while(ichangeC % 1000 != ichangeC) { hdollars++; DaDCount++; ichangeC = ichangeC - 1000; } while(ichangeC % 500 != ichangeC) { ldollars++; DaDCount++; ichangeC = ichangeC - 500; } while(ichangeC % 100 != ichangeC) { gdollars++; DaDCount++; ichangeC = ichangeC - 100; } while(ichangeC % 25 != ichangeC) { quarters ++; DaCount++; ichangeC = ichangeC - 25; } while(ichangeC % 10 != ichangeC) { dimes++; DaCount++; ichangeC = ichangeC - 10; } while(ichangeC % 5 != ichangeC) { nickles++; DaCount++; ichangeC = ichangeC - 5; } while(ichangeC % 1 != ichangeC) { pennies++; DaCount++; ichangeC = ichangeC - 1; } }