need some pointers

xSauronx

Lifer
Jul 14, 2000
19,582
4
81
yes, this is homework, but ive always avoided programming and had no prior knowledge going into the class. im starting to get the hang of it, but its really not my thing so figuring out new bits of logic is still taking me some time.

i googled around and found some examples, but theyre all in other languages (python, java, stuff i understand less than the QBASIC we use in the intro class)

i know i need to define some things, like values of all the change, but im not really sure about the logic needed to do the actual work.

problem: define customer records where each customer buys an item for less than a dollar, and pays for it with one dollar. output should return the change amount (yes, i can do *that* part) and the amount of change given in quarters, dimes, nickles and pennies.

i just cant find an example where i understand the logic well enough to get anything done, anyone mind pointing me in the right direction?
 

KLin

Lifer
Feb 29, 2000
30,951
1,079
126
1. Populate change variable
2. Create a loop that evaluates if change variable is greater than denomination, Increment count of greatest denomination coin required by 1, subtracts from change variable, repeat evaluation until change variable is 0.
3. Need to keep track of each denomination count in order to output it.


 

blahblah99

Platinum Member
Oct 10, 2000
2,689
0
0
Have an array for the denominations, have an array for the coin count. Loop through each denomination and find the max. coin count, taking the running total change so far into account.

Now if you have to implement that using digital logic gates, that'll be fun.
 

xSauronx

Lifer
Jul 14, 2000
19,582
4
81
Originally posted by: blahblah99
Have an array for the denominations, have an array for the coin count. Loop through each denomination and find the max. coin count, taking the running total change so far into account.

Now if you have to implement that using digital logic gates, that'll be fun.

we havent gotten to arrays yet and i dont know the syntax for anything you just suggested except running a loop :p

Create a loop that starts with largest denomination, counts number of coins needed

i have no idea how to do this. either i dont know the needed syntax (i missed a couple days being sick), or i just dont have the hang of this yet. ill get the teacher to tell me what im missing tomorrow.

thanks anyway guys :)
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
Have you learned the use of the % operator yet? It returns the remainder of an operation.

So 10/3 has a remainder of 1. 10 % 3 = 1.
9 % 3 = 0.
This might be useful for you. (I'm pretty sure I'm using that correctly...I'm sure ppl will point out if I'm not)

In terms of logic, you could at the basic leveldo this:

calculate the change (duh) and then...

if > 25, divide by 25 (answer = # quarters).

Take the remainder - if > 10, divide by 10 (answer = # dimes)

Take the remainder ... rinse, wash, repeat with nickels and pennies
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Let change = the amount of change you need to make coins for. I'll use floor as the function truncates the result of a math function (e.g., floor(2.1) = 2, floor(5.8) = 5, etc.). Depending on your programming language you may or may not need to use floor explicitly. Treat this as pseudocode.

numQuarters = floor(change / 25);
change -= 25 * numQuarters;
numDimes = floor(change / 10);
change -= 10 * numDimes;
numNickels = floor(change / 5);
change -= 5 * numNickels;
numPennies = change;

print numQuarters, numDimes, numNickels, numPennies and you're done.
 

xSauronx

Lifer
Jul 14, 2000
19,582
4
81
Originally posted by: KLin
So much for doing your own homework.

Meh. Im the go-to guy for a number of my classes and get all As. The textbook is a vbasic intro, not qbasic. Im not averse to asking for help, and Im not embarrassed to say "i have no idea what im doing." Your first example was useful, I just dont know the syntax to implement it.

Ill play with the % operator on my break. We havent covered functions anyway, and i have no idea what "-=" is supposed to mean so esun's example doesnt do me but so much good.

Christ. I can make change, but without knowing what does what in the language I have to use, I cant really accomplish much.

I found a qbasic guide online last night that Im going to read over, it looks like it covers a lot of the syntax so hopefully it will be pretty helpful *crosses fingers*

otherwise, thanks guys, i appreciate the help :)
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
Originally posted by: xSauronx
Originally posted by: KLin
So much for doing your own homework.

Meh. Im the go-to guy for a number of my classes and get all As. The textbook is a vbasic intro, not qbasic. Im not averse to asking for help, and Im not embarrassed to say "i have no idea what im doing." Your first example was useful, I just dont know the syntax to implement it.

Ill play with the % operator on my break. We havent covered functions anyway, and i have no idea what "-=" is supposed to mean so esun's example doesnt do me but so much good.

Christ. I can make change, but without knowing what does what in the language I have to use, I cant really accomplish much.

I found a qbasic guide online last night that Im going to read over, it looks like it covers a lot of the syntax so hopefully it will be pretty helpful *crosses fingers*

otherwise, thanks guys, i appreciate the help :)

a -= b; is like saying a = a - b;
It is just a shorthand for writing that (as it is really common to do)

look up "Q Basic operators" and go from there. Once you have a firm understanding of operators, things should start getting a little easier.
 

KLin

Lifer
Feb 29, 2000
30,951
1,079
126
Originally posted by: xSauronx
Originally posted by: KLin
So much for doing your own homework.

Meh. Im the go-to guy for a number of my classes and get all As. The textbook is a vbasic intro, not qbasic. Im not averse to asking for help, and Im not embarrassed to say "i have no idea what im doing." Your first example was useful, I just dont know the syntax to implement it.

Ill play with the % operator on my break. We havent covered functions anyway, and i have no idea what "-=" is supposed to mean so esun's example doesnt do me but so much good.

Christ. I can make change, but without knowing what does what in the language I have to use, I cant really accomplish much.

I found a qbasic guide online last night that Im going to read over, it looks like it covers a lot of the syntax so hopefully it will be pretty helpful *crosses fingers*

otherwise, thanks guys, i appreciate the help :)

If this is visual basic, look into the DO WHILE/LOOP Statement and IF/THEN statements.
 

xSauronx

Lifer
Jul 14, 2000
19,582
4
81
Originally posted by: KLin

If this is visual basic, look into the DO WHILE/LOOP Statement and IF/THEN statements.[/quote]

no thats the thing, this is intro programming with qbasic, but the *book* for the course is for visual basic :-/

i can do the loops and if/then stuff....actually thats just about all i can do :eek:

 

KLin

Lifer
Feb 29, 2000
30,951
1,079
126
Originally posted by: xSauronx
Originally posted by: KLin


If this is visual basic, look into the DO WHILE/LOOP Statement and IF/THEN statements.

no thats the thing, this is intro programming with qbasic, but the *book* for the course is for visual basic :-/

i can do the loops and if/then stuff....actually thats just about all i can do :eek:

Wow.
 

xSauronx

Lifer
Jul 14, 2000
19,582
4
81
Originally posted by: Ken g6
Wow is right.

I was just looking for examples of QBasic to help you when I ran across something better: a free online QBasic book!

groovy, thanks.

and yeah, wow. she mentioned maybe dropped qbasic for something else in the future, i think a class for some kind of basic scripting might be more useful than qbasic, but, whatever.

i asked a programmer thats in one of my network classes, he said what she wants is just a loop for each type of coin using the change variable to always hold the remainder.

ive just gotten used to doing nested if/then stuff inside one loop, so i fixed functionaly-ness about it all which is what was holding me up, otherwise KLin's first suggestion would have made more sense to me. oops!


 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
Groovy? Personally, I'd recommend Python or Perl as a first language, and I think we had a thread about that awhile back. But I guess Groovy could work too. ;)
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Ken g6
... Personally, I'd recommend Python or Perl as a first language, and I think we had a thread about that awhile back. ...

*runs and hides*
 

KLin

Lifer
Feb 29, 2000
30,951
1,079
126
well since everybody else is helping people with they're homework:

Public Function ChangeCalc(ByVal ChangeReq As Double)
Dim QCount As Long
Dim DCount As Long
Dim NCount As Long
Dim PCount As Long
Dim ChangeInt As Long

ChangeInt = ChangeReq * 100
Do While ChangeInt > 0

If ChangeInt >= 25 Then
QCount = QCount + 1
ChangeInt = ChangeInt - 25
ElseIf ChangeInt >= 10 Then
DCount = DCount + 1
ChangeInt = ChangeInt - 10
ElseIf ChangeInt >= 5 Then
NCount = NCount + 1
ChangeInt = ChangeInt - 5
ElseIf ChangeInt >= 1 Then
PCount = PCount + 1
ChangeInt = ChangeInt - 1
End If
Loop

MsgBox "Quarters Required: " & QCount & vbCrLf & _
"Dimes Required: " & DCount & vbCrLf & _
"Nickels Required: " & NCount & vbCrLf & _
"Pennies Required: " & PCount & vbCrLf
End Function

That's how I did it. :p
 

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
Originally posted by: KLin
well since everybody else is helping people with they're homework:

Public Function ChangeCalc(ByVal ChangeReq As Double)
Dim QCount As Long
Dim DCount As Long
Dim NCount As Long
Dim PCount As Long
Dim ChangeInt As Long

ChangeInt = ChangeReq * 100
Do While ChangeInt > 0

If ChangeInt >= 25 Then
QCount = QCount + 1
ChangeInt = ChangeInt - 25
ElseIf ChangeInt >= 10 Then
DCount = DCount + 1
ChangeInt = ChangeInt - 10
ElseIf ChangeInt >= 5 Then
NCount = NCount + 1
ChangeInt = ChangeInt - 5
ElseIf ChangeInt >= 1 Then
PCount = PCount + 1
ChangeInt = ChangeInt - 1
End If
Loop

MsgBox "Quarters Required: " & QCount & vbCrLf & _
"Dimes Required: " & DCount & vbCrLf & _
"Nickels Required: " & NCount & vbCrLf & _
"Pennies Required: " & PCount & vbCrLf
End Function

That's how I did it. :p

You were bored and wanted to show off :p.
 
Sep 29, 2004
18,656
68
91
1) dump a bunchof coins on your desk

2) do a couple of tests to see how you would logically build 43 cents, $1.23, $0.79, etc.

3) write hte softwre to do what you would do normally.

HINT) don't start with pennies!