Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to know how to write a utility that converts dollars to coins that must c

ID: 3539958 • Letter: I

Question

I need to know how to write a utility that converts dollars to coins that must consist of the following: multiple out to the screen; one input; the use of integers and strings; looking or repetition with Do, While, If, Else; Must have some output text to show correct value of coins that would be converted from the dollar;; code must include comments explaining your reason for the code section or what the code is doing; Code must compile; Dollar amounts should be round numbers with 2 decimals points (ie 47.00, 47.37, 47.50). If value is less than 1 or 0 the proggram should break or exit.

Explanation / Answer

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
double dollar_amount;
string list[] = {"dollars","Quarters","Dimes","Nickels","Pennies"};
int a[5] = {0};
cout << "Enter the number of dollars";
cin>> dollar_amount;
cout<<endl;
if(dollar_amount<=1)
{
cout <<" enter amount is less than 1. so Exiting" << endl;
return 0;
}
// find how many dollars it has
a[0] = static_cast<int>(dollar_amount);
// once we got dollars see how much left.
int money_left=(dollar_amount-a[0])*100+.005;
// check for no of quarters and save it in a[1]
a[1] = money_left/25;
//see for left amount.
money_left = money_left%25;
// check for no of Dimes and save it in a[2]
a[2] = money_left/10;
//see for left amount.
money_left = money_left%10;
// check for no of Nickels and save it in a[3]
a[3] = money_left/5;
// check for no of Pennies and save it in a[4]
a[4] = money_left%5;
// now print result.
cout << setprecision(6) << dollar_amount << " is equal to ";
for(int i=0; i<5; i++)
{
if(a[i]!=0)
cout << a[i] << " " << list[i] << " ";
}
return 0;
}