473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need Help with C++ Cashier Program

2
In this program, I am suppose to enter an amount that the customer owes, how much he/she paid, and their change. I already figured that out, what I can't figure out is that the program should also calculate & display the amount in how many dollars, quarters, dimes, nickels, & pennies to return to the customer.

//output items

cout <<"Customer's change: \n\n" <<result<<endl;

cout <<"___________________________\n\n";

cout <<"Dollars: " <<result / 1<<endl;
cout <<"\n";

cout <<"Quarters: " <<result / .25<<endl;
cout <<"\n";

cout <<"Dimes: " <<(result / .10)<<endl;
cout <<"\n";

cout <<"Nickels: " <<(result / 0.05)<<endl;
cout <<"\n";

cout <<"Pennies: " <<(result / 0.01)<<endl;
cout <<"\n\n\n";

if anyone could please help me i'm too new to programing i been trying really hard to figure it out, if anyone could help me please let me know so i can send the rest of the code thank.
Jan 22 '08 #1
4 4789
oler1s
671 Expert 512MB
The problem isn't the code. It's your logic.

Let's use real numbers to figure this out.

Let's say the charge is $2.80 and I pay a $5. Ok, so that's $2.20 in change, right?

So, that's $2 in change. And then 2.20/.25 = 8.8 quarters. Wait a minute, why are you dividing 2.20 by .25?
Jan 22 '08 #2
jp112
2
what do you recommend how should i rewrite it for it to show that for a change of 2.25 it should give $2 and a quarter?

example
Jan 22 '08 #3
oler1s
671 Expert 512MB
This is basic logic you need to figure out yourself.

Write down the steps you take in plain english when solving for the change.

For example, the amount due is $3.23 and I pay $5. Now calculate in plain english the change. Don't just give the answer. Figure out how many dollars in change. What numbers did you add or subtract? Why? Then figure out quarters. What numbers did you add or subtract? Why? Then dimes. Then nickels. Then pennies.

Write it all down here in plain english. If you get it down correctly, with the right level of detail, it should be obvious how to write the code. If you don't, we'll tell you what more to think about.
Jan 22 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Hey, you guys. Keep the money in pennies.

$2.80 is an int with 280 in it. The fancy display of $2.80 is done by a display function you write.

Paying with $5 is 500 for a $3.23 item is just 500-323, or 177.

177 % 100 = 1 ---> the dollars
177 - 1 * 100 = 77 ---> the remaining pennies
77 % 25 = 3 ---> the quarters
77 - 3*25 = 2 --->the remaining pennies
2 % 10 = 0 --->the dimes
2 % 5 = 0 --->the nickles
2 --->the pennies

Therefore, give 1 dollar, 3 quarters and 2 pennies in change.

Do not ever use floating point in a finance application.
Jan 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sean | last post by:
Hi, I have an xml file. <cashier> <tag param1="work-14" param1="0" param2="1000199" param3="1" param4="2141690" param5="3" param5="3" param6="011111" param7="4" /> <tag param1="work-14"...
2
by: aj902 | last post by:
Hello , I am trying to create a program where all detail, http://www.albany.edu/~csi333/projects.htm
2
by: michael.rygh | last post by:
This is just one of the sources for a project that deals with a library. I am having problems, here is the errors. all these.. i belive it has something to do with it needs a subscript? but i'm...
13
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
4
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
3
by: begum | last post by:
Hi everyboyd. I have some problem about my program. i write a part of the program but ý don't know how to do it ( ý have problem about coding). here is my program #include <iostream> using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.