63 797
Assignments Done
99,4%
Successfully Done
In August 2018

Answer to Question #10462 in C++ for marci trussell

Question #10462
Please help in doing this and if your able too let me know: For the program, you will write a utility that converts dollars to coins. It is 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.
Expert's answer
void ConvertToCoins(double);

#include <iostream> //allows program to perform input and output

using std::cout; //program uses cout

using std::cin; //program uses cin

using std::endl; //program uses endl

//function main begins program execution

void main()

{

double amount ;

int iFlag = -1;

do

{

system("cls") ;

cout << "Enter a $ amount..." << endl ;

cout << "$" ;

cin >> amount ;

if(amount < 0) break ;

ConvertToCoins(amount) ;

cout << "Enter -1 to exit..." << endl ;

cin >> iFlag;

}while(iFlag != -1);

}

void ConvertToCoins(double amt)

{

static int quarters = 0;

static int dimes = 0 ;

static int nickels = 0 ;

static int pennies = 0 ;

if(amt >= .25)

{

quarters++ ;

ConvertToCoins(amt - .25) ;

}

else if(amt >= .10)

{

dimes++ ; ConvertToCoins(amt - .10) ;

}

else if(amt >= .05)

{

nickels++ ; ConvertToCoins(amt - .05) ;

}

else if(amt >= .01)

{ pennies++ ; ConvertToCoins(amt - .01) ;

}

else

{

cout << "Coin TOTAL" << endl ;

cout << "---------------------------" << endl ;

cout << "Quarters = " << quarters << " $" << (quarters * .25) << endl ;

cout << "Dimes = " << dimes << " $" << (dimes * .10) << endl ;

cout << "Nickels = " << nickels << " $" << (nickels * .05)
<< endl ;

cout << "Pennies = " << pennies << " $" << (pennies * .01) << endl ;

cout << "---------------------------" << endl ;

cout << "TOTAL COINS = " << (quarters + dimes + nickels + pennies) << endl ;

}

}

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