Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; int main() { //declare variables double dollarAmount; int quarters, dimes, nickels, pennies, totalCents; //Prompt the user to enter the amount of

#include

using namespace std;

int main() { //declare variables double dollarAmount; int quarters, dimes, nickels, pennies, totalCents;

//Prompt the user to enter the amount of money they have before the conversion cout << "Due to the Martian Money Weevel plague, we need to turn your money into all coins. "; cout << "Please enter the amount of money you have so that you don't break the law. $"; cin >> dollarAmount;

//turn the dollar amount into cents totalCents = dollarAmount * 100; //calculate and store the amount of full quarters in the amount quarters = totalCents / 25; //calculate and store the remaining change totalCents = totalCents % 25; //calculate and store the amount of full dimes in the remaining change dimes = totalCents / 10; //calculate and store the remaining change totalCents = totalCents %10; //calculate and store the amount of full nickels in the remaining change nickels = totalCents / 5; //calculate and store the remaining amount into pennies pennies = totalCents%5;

//Print the amount of each type of coin to give the smallest amount of change cout << "Alright this is the least amount of change I can give you: "; cout << quarters << " Quarter(s) "; cout << dimes << " Dime(s) "; cout << nickels << " Nickel(s) "; cout << pennies << " Pennie(s)";

return 0; }

/* Sample run Due to the Martian Money Weevel plague, we need to turn your money into all coins. Please enter the amount of money you have so that you don't break the law. $123.44 Alright this is the least amount of change I can give you: 493 Quarter(s) 1 Dime(s) 1 Nickel(s) 3 Pennie(s) Process returned 0 (0x0) execution time : 2.330 s Press any key to continue. */

I can't figure out whats wrong with my program. It keeps rounding incorrecltly for the pennies.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions