|
-
Mar 3rd, 2006, 08:21 PM
#1
Thread Starter
New Member
[RESOLVED] Simple Program
New to the forums, and wanted to ask the .NET pros out there a rather simple question, something I'm stuck on. For my college class, we have to make a program that takes a number of pennies you enter, and puts out the number of dollars, quarters, dimes, nickels, and remaining pennies in that total number of pennies.
In example.....i type in 180 to the main textbox, and below, it will show 1 dollar, 3 quarters, and 1 nickel.
Now the problem, I set all my variables as Integer, and started doing the equations. The dollars comes out correctly, and the quarters come out correctly, but my dimes, nickles, and remaining pennies will not even show up. Am i missing something?
This is the code I have entered so far
-----------
Dim totalpennies As Integer
Dim dollars As Integer
Dim quarters As Integer
Dim dimes As Integer
Dim nickles As Integer
Dim pennies As Integer
totalpennies = CSng(txtPennies.Text)
dollars = totalpennies \ 100
totalpennies = totalpennies Mod 100
quarters = totalpennies \ 25
totalpennies = quarters Mod 25
dimes = totalpennies \ 10
totalpennies = dimes Mod 10
nickles = totalpennies \ 5
totalpennies = nickles Mod 5
-------------------------
So everything works except for "dimes = totalpennies \ 10" and down
I'm probably doing something stupid wrong, help!
-
Mar 3rd, 2006, 10:35 PM
#2
Frenzied Member
Re: Simple Program
I think it was a simple math mistake. But I'm no math genius.
dollars = totalpennies \ 100
totalpennies = totalpennies Mod 100
quarters = totalpennies \ 25
totalpennies = totalpennies Mod 25
dimes = totalpennies \ 10
totalpennies = totalpennies Mod 10
nickles = totalpennies \ 5
totalpennies = totalpennies Mod 5
Welcome to the forums
-
Mar 3rd, 2006, 10:38 PM
#3
Re: Simple Program
You should be using totalpennies each time you use Mod. totalpennies should be on the right of every line. Also, you've declared totalpennies as an Integer yet your converting the string from the TextBox to a Single and then assigning that to totalpennies. You should be converting to an Integer.
-
Mar 3rd, 2006, 11:52 PM
#4
Thread Starter
New Member
Re: Simple Program
ahhhhhhhh like i said stupid error. thanks for the help guys, much appreciated
-
Mar 4th, 2006, 12:07 AM
#5
Re: Simple Program
Cool. Don't forget to resolve your thread from the Thread Tools menu.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|