#include<cstdlib> #include <iostream> using namespace std; int a[4]; class chang
ID: 3616807 • Letter: #
Question
#include<cstdlib>
#include <iostream>
using namespace std;
int a[4];
class changeMaker{
public:
double changeMake(int amount){
//Base Case
if(amount == 0)
return 0;
if(amount >= 25){
amount = amount-25;
returnchangeMake(amount);
}
if(amount >= 10){
a[1]++;
amount = amount -10;
returnchangeMake(amount);
}
if(amount>=5){
a[2]++;
amount = amount - 5;
return changeMake(amount);
}
if(amount>=1 ){
a[3]++;
amount = amount -1;
returnchangeMake(amount);
}
return0;
}
};
int main(){
double f;
changeMaker bank;
cout<<"Enter Dollar Amount ";
cin>>f;
int t=f*100;
cout<<" The amount entered is "<< f<< endl;
bank.changeMake(t);
cout<< "Quater: " << a[0]<<endl;
cout << "Dimes: " <<a[1]<<endl;
cout << "nickel: " <<a[2]<<endl;
cout << "pennies: " <<a[3]<<endl;
}
Explanation / Answer
please rate - thanks not every real number can be represented in the computer, so yousometimes "lose" data. The solution is to do some rounding. Ialso added your loop #include #include using namespace std; int a[4]; class changeMaker{ public: double changeMake(int amount){ //Base Case if(amount == 0) return 0; if(amount >= 25){ a[0]++; amount = amount-25; returnchangeMake(amount); } if(amount >= 10){ a[1]++; amount = amount -10; returnchangeMake(amount); } if(amount>=5){ a[2]++; amount = amount - 5; return changeMake(amount); } if(amount>=1 ){ a[3]++; amount = amount -1; returnchangeMake(amount); } return 0; } }; int main(){ double f; char in; changeMaker bank; coutf; for(int i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.