Results 1 to 5 of 5

Thread: [RESOLVED] Simple Program

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Resolved [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!

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    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
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    Re: Simple Program

    ahhhhhhhh like i said stupid error. thanks for the help guys, much appreciated

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Simple Program

    Cool. Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width