![]() |
|
#1
|
|||
|
|||
Repetition StructureI am a beginner with C++ that is in need of some advice. I am writing a program for my class that just work work. The program us intended to have have the following output:
Amount Owed: Amount Received: Change: Fifty: Twenty: Ten: Five: Dollar quarter: Dime: Nickel: Penny: We need the program to run again without exiting in order to proceed with the next customer. Here is some of the code I have in the function: CPP / C++ / C Code:
Is this even close or I am way off. I just need to be put in the right direction. Any help will be greatly appreciaed. Eric Sorry for the long thread.. Last edited by dsmith : 23-Mar-2004 at 08:53.
Reason: Updated syntax highlighting tag
|
|
#2
|
||||
|
||||
|
Aww... you were so close to the syntax hilighting! Your closing tag needs to look like this!: [/c]
As far as the code, it's close. Where's the ending brace on your while loop? Also, when you use a return statement with operators, you should enclose that statement in parenthesis like so: CPP / C++ / C Code:
__________________
-Aaron |
|
#3
|
||||
|
||||
|
Ahhh, the change program. Next time try the Preview button to see if your post is correct.
Quote:
If you feel you need help, ask a specific question so we know what you're having trouble with. __________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
|
i fail to understand the logic behind both of your functions. Maybe you should rethink the logic behind them. Spotted an error:
the line after CPP / C++ / C Code:
also where have u declared the counter? and why are u decrementing it? and why is amount being incremented by 1? you should first try to do this on a piece of paper. work out the proper logic in your own words: for example: i will first get the amount owed. then i will run a while loop till the amount that is owed is satisfied. (while inside the loop) if i receive amount less than what is owed, i will credit that to the amount owed and keep asking the user for the remaining amount till i get it all if i recieve more than what is owed i will credit what is owed and return the rest while loop ends it's called pseudocode if im not mistaken make it a habit to spend more time with ur pen and paper than with ur compiler. You will save lots of frustration and time. Many programmers especially the beginners only think a few minutes about the problem and then get right to programming thinking they can figure it out on the fly and just keep on compiling and fixing errors till there are no errors anymore. concentrate on the general big picture first. Then divide your big picture into smaller parts or functions. Concentrate on smaller functions one by one. and then make changes after you are done to make them work with each other. Quote:
|
|
#5
|
|||
|
|||
|
Quote:
Well, Eric, It's hard to say how close you are; but I think I see what you have in mind, and it's possible that you are not too far off. The idea of using / and % to get a number and its remainder can be applied to your problem, but they work with ints. Here's a suggestion: why not convert all calculations to pennies (so you are always working with integers internally)? Does this make sense to you? (I've done it many times, so it makes sense to me, but ...) Dave |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| my compiler says I have to have a variable at the end of my structure | ambeco | C Programming Language | 10 | 24-Feb-2004 10:37 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The