Hi,
I've been working on this program for approximately 2 weeks and I just can't do it, I'm a beginner it's really difficult for me and I don't know what to do anymore. The part where you supposed to get your cents back doesn't want to work and I really don't know why, I was trying to optimize as best as I can my code to have less code line but I'm not capable to do it. Some help would be very appreciate please.
Many Thanks in Advance.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main() {
cout<<setprecision(2)<<fixed;
double iAmount_due {0 },iGiven_money { 0 };
double moneyCat[]{100, 50, 20, 10, 5, 2, 1, 0.25, 0.10, 0.05, 0.01};
cout << "Enter the amount due please: ";
cin >> iAmount_due;
cout << "Enter the amount given please: ";
cin >> iGiven_money;
double iMoney_back = (round(iGiven_money*100 -iAmount_due*100))/100;
if(iMoney_back) cout << "We will give you : " << iMoney_back << " $ back" << endl;
else cout << "No money back" << endl;
int count = 0;
for(int i = 0; i<11; i++) {
if (iMoney_back >= moneyCat[i]) {
iMoney_back = iMoney_back - moneyCat[i];
count++;
if (moneyCat[i] > iMoney_back ) {
cout << "you will get: " <<count << " X " << moneyCat[i]<<"$" << endl;
count = 0;
}
else i--;
}
}
return 0;
}
output:
Enter the amount due please: 65.65
Enter the amount given please: 100
We will give you : 34.35 $ back
you will get: 1 X 20.00$
you will get: 1 X 10.00$
you will get: 2 X 2.00$
you will get: 1 X 0.25$
you will get: 1 X 0.10$