Hi,
I need some help making a program that outputs change in the least amount of dollars and coins. Here is what I have so far but it doesnt work correctly and I don't know why. Thanks.
Code:#include <iostream> using namespace std; int main() { double charged, given, difference; cout << "Enter amount charged:\n"; cin >> charged; cout << "Enter amount given:\n"; cin >> given; difference = given - charged; double money[10] = {100,50,20,10,5,1,.25,.10,.05,.01}; double change[10] = {0,0,0,0,0,0,0,0,0,0}; for(int i =0; i<10; i++) { while(money[i] < difference) { change[i]++; difference -= money[i]; } } for(int i = 0; i<10; i++) if(change[i] != 0) cout << "$" << money[i] << ": " << change[i] << "\n"; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.