77 922
Assignments Done
98,3%
Successfully Done
In August 2019

Answer to Question #37679 in C++ for Corey

Question #37679
I am to write a utility that converts dollars to coins. A simple program that must have the following:

* Multiple outputs to the screen
* At least 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 dollars.
* Code must include comments explaining your reason for the code section or what the code is doing
* Code must compile
* Whole dollars only. If value is less than 1 or 0, the program should break or exit.

Source code (.cpp file)

<iostream>
using std::cin;
using std::cout;
using std::fixed;
using std::end1;
#include <iomanip> // parameterized stream manipulators
using std::setprecision; // set numeric output precision

void ConvertToCoins(double);

int main ( )
{
double amount;
while(true)
{
//Add your code here to ask the user for the amount and input the amount.

if(amount < 0) break;
ConvertToCoins(amount);
}
return 0;
}
void ConvertToCoins (double amt)
{
static int quarters = 0;
static int dimes = 0;
static int nickles = 0;
static int pennies = 0;

if(amt >= .25)
{
quarters++;
ConvertToCoins(amt - .25);
}
else if(amt >= .10)
{

//Continue checking to see if we have enough money left over to convert to smaller coins.

dimes++;
ConvertToCoins(amt - .10);
}
if(amt >= .05)
{
nickles++;
ConvertToCoins(amt - .05);
}

else if(amt >= .01)
{
pennies++;
ConvertToCoins(amt - .01);

}

cout<<"Coin TOTAL"<<end1;
cout << "----------------" <<end1;
cout << "Quarters=" << quarters << "$" << (quarters * .25) <<end1;
cout << "Dimes=" << dimes << "$" << (dimes * .10 )<<end1;
cout << "Nickles=" << nickles << "$" << (nickles * .05) <<end1;
cout << "Pennies=" <<pennies << "$" <<( pennies * .01) <<end1;
cout << "--------------------" <<end1;
cout << "TOTAL COINS=" << (quarters + dimes + nickles + pennies) <<end1;
//Add code here to display the results. Show the number of each coin and the dollar amount for each coin.
Expert's answer

Not answered

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions