Back again, rather soon, after the past 2 easier weeks. This time, it is the infamous Change Dispenser program. It's plastered all over the web as the intro program teacher of choice, but I'm not feeling its power.
Any words of wisdom to get me to a problem solving state of mind? I've included what I've got so far, but unsure of some - in particular, static_cast<int>.
Any words of wisdom to get me to a problem solving state of mind? I've included what I've got so far, but unsure of some - in particular, static_cast<int>.
Code:
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
double due, paid, difference;
int change, dollars, q, n, d, p;
int main ()
{
printf ("Welcome. \n");
printf ("Enter the amount due: \n");
scanf("%lf", &due);
printf ("Enter the amount paid: \n");
scanf("%lf", &paid);
double difference = paid - due;
int change = static_cast<int> (difference * 100);
int dollars = change / 100;
change = change - ( dollars * 100);
int q = change / 25;
change = change - ( q * 25);
int d = change / 10;
change = change - ( d * 10);
int n = change / 5;
change = change - ( n * 5);
int p = change / 1;
change = change - ( p * 1);
printf ("The return change is as follows. \n");
printf ("Amount of Dollars: %.2lf \n", dollars);
printf ("Amount of Quarters: %.2lf \n", q);
printf ("Amount of Dimes: %.2lf \n", d);
printf ("Amount of Nickels: %.2lf \n", n);
printf ("Amount of Pennies: %.2lf \n", p);
return 0;
}