answersLogoWhite

0


Best Answer

void calcCoins(int amount) {

const int valQ = 25;

const int valD = 10;

const int valN = 5;

const int valP = 1;

int numQ = 0;

int numD = 0;

int numN = 0;

int numP = 0;

// Count number of quarters.

while( amount >= valQ ) {

++numQ;

amount -= valQ;

}

// Count number of dimes.

while( amount >= valD ) {

++numD;

amount -= valD ;

}

// Count number of nickels.

while( amount >= valN ) {

++numN;

amount -= valN ;

}

// Count number of pennies.

while( amount >= valP ) {

++numP;

amount -= valP ;

}

printf("Quarters: %d\n", numQ);

printf("Dimes: %d\n", numD);

printf("Nickels: %d\n", numN);

printf("Pennies: %d\n", numP);

printf("Total coins: %d\n", (numQ + numD + numN + numP));

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you write me an algorithm C plus plus to calculate the change in quarters dimes nickels pennies when the amount 90 cents is entered It should return the minimum coins for the amount entered?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you calculate the minimum bounding box of a convex polygon?

With the two rotating calipers algorithm: http://cgm.cs.mcgill.ca/~orm/rotcal.html


When is minimum mean square error algorithm used?

This type of algorithm is commonly used in n dimensional clustering applications. This mean is commonly the simplest to use and a typical algorithm employing the minimum square error algorithm can be found in McQueen 1967.


What is krushkal algorithm?

Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component). Kruskal's algorithm is an example of a greedy algorithm.


What is the minimum number of quarters pennies and nickels needed to make up 123 cents?

The minimum number of quarters, pennies, and nickels needed to make up 123 cents is 4 quarters, 4 nickels, and 3 pennies.


What is MOQ?

* Minimum Order Quantity * Married Officer's Quarters


What is cost optimal algorithm in parallel computing?

The cost optimal algorithm in parallel computing is the modular structured parallel algorithm that satisfy the insatiable demand of low power consumption, reduces speed and minimum silicon area.


Who is the inventor of Reverse Delete Algorithm for MST When was this first published?

The Reverse Delete Algorithm for finding the Minimum Spanning Tree was first introduced by Edsger Dijkstra in 1959. He presented this algorithm in his paper titled "A note on two problems in connexion with graphs" which was published in Numerische Mathematik.


How do you calculate the maximum and minimum possible for total mass?

minimum is less


Can dijkstra's algorithm produce a spanning tree?

yes, but a shortest path tree, not a minimum spanning tree


What is the complexity of kruskal's minimum spanning tree algorithm on a graph with n nodes and e edges?

o(eloge)


What is the usefulness of minimum moment algorithm in resource levelling?

resource leveling is an effective means of smoothing the utilization of resources


Examples of how to calculate minimum maximum inventory level?

Minimum: (AMU/30.4)*(Leadtime*SafetyStock) Maximum is the Difference between the Minimum and Buy Qty