Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1099957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:48:38+00:00 2026-05-17T00:48:38+00:00

I am creating a VB 2008 change calculator as an assignment. The program is

  • 0

I am creating a VB 2008 change calculator as an assignment. The program is to use the amount paid – the amount due to calculate the total.(this is working fine). After that, it is to break that amount down into dollars, quarters, dimes, nickels, and pennies. The problem I am having is that sometimes the quantity of pennies, nickels or dimes will be a negative number. For example $2.99 = 3 Dollars and -1 Pennies.

SOLVED

Thanks to the responses, here is what I was able to make work with my limited knowledge.

Option Explicit On
Option Strict Off
Option Infer Off

Public Class frmMain

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'Clear boxes

        lblDollarsAmount.Text = String.Empty
        lblQuartersAmount.Text = String.Empty
        lblDimesAmount.Text = String.Empty
        lblNickelsAmount.Text = String.Empty
        lblPenniesAmount.Text = String.Empty
        txtOwed.Text = String.Empty
        txtPaid.Text = String.Empty
        lblAmountDue.Text = String.Empty
        txtOwed.Focus()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Close application' 
        Me.Close()
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        ' Find Difference between Total Price and Total Received 
        lblAmountDue.Text = Val(txtPaid.Text) - Val(txtOwed.Text)
        Dim intChangeAmount As Integer = lblAmountDue.Text * 100

        'Declare Integers  
        Dim intDollarsBack As Integer
        Dim intQuartersBack As Integer
        Dim intDimesBack As Integer
        Dim intNickelsBack As Integer
        Dim intPenniesBack As Integer

        ' Change Values 
        Const intDollarValue As Integer = 100
        Const intQuarterValue As Integer = 25
        Const intDimeValue As Integer = 10
        Const intNickelValue As Integer = 5
        Const intPennyValue As Integer = 1

        'Dollars 
        intDollarsBack = CInt(Val(intChangeAmount \ intDollarValue))
        intChangeAmount = intChangeAmount - Val(Val(intDollarsBack) * intDollarValue)
        lblDollarsAmount.Text = intDollarsBack.ToString

        'Quarters 
        intQuartersBack = CInt(Val(intChangeAmount \ intQuarterValue))
        intChangeAmount = intChangeAmount - Val(Val(intQuartersBack) * intQuarterValue)
        lblQuartersAmount.Text = intQuartersBack.ToString

        'Dimes 
        intDimesBack = CInt(Val(intChangeAmount \ intDimeValue))
        intChangeAmount = intChangeAmount - Val(Val(intDimesBack) * intDimeValue)
        lblDimesAmount.Text = intDimesBack.ToString

        'Nickels 
        intNickelsBack = CInt(Val(intChangeAmount \ intNickelValue))
        intChangeAmount = intChangeAmount - Val(Val(intNickelsBack) * intNickelValue)
        lblNickelsAmount.Text = intNickelsBack.ToString

        'Pennies 
        intPenniesBack = CInt(Val(intChangeAmount \ intPennyValue))
        intChangeAmount = intChangeAmount - Val(Val(intPenniesBack) * intPennyValue)
        lblPenniesAmount.Text = intPenniesBack.ToString

    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:48:38+00:00Added an answer on May 17, 2026 at 12:48 am
    Public Shared Function CalculateChange(ByVal dblDollarsPaid As Double, ByVal dblDollarsOwed As Double)
        Dim intChangeCents As Integer
        Dim change As New Change()
    
        intChangeCents = CInt((dblDollarsPaid - dblDollarsOwed) * 100)
    
        change.Dollars = intChangeCents \ 100
        intChangeCents = intChangeCents Mod 100
    
        change.Quarters = intChangeCents \ 25
        intChangeCents = intChangeCents Mod 25
    
        change.Dimes = intChangeCents \ 10
        intChangeCents = intChangeCents Mod 10
    
        change.Nickels = intChangeCents \ 5
        intChangeCents = intChangeCents Mod 5
    
        change.Pennies = intChangeCents
    
        Return change
    End Function
    

    Usage:

    Dim c As Change
    c = CalculateChange(13.26, 2.99)
    Console.WriteLine("{0} dollars, {1} quarters, {2} dimes, {3} nickels and {4} pennies", _
                       c.Dollars, c.Quarters, c.Dimes, c.Nickels, c.Pennies)
    

    \ is the operator for integer division, e.g. 5 \ 2 is 2, not 2.5.

    The Change structure is from Alex Essilfie’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use visual studio 2008 for creating projects that can run on windows.
I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER
Working with C# Visual Studio 2008, MVC1. I'm creating an xml file by fetching
I am creating an MSI from inside visual studio 2008. This is what I
When creating a subscription on reporting services 2008 one is unable to select all
Basically I am creating a database driven website in Web Developer 2008. The database
I am creating a Windows Mobile Application in C# and Visual Studio 2008. The
I've a large (1TB) table in SQL Server 2008 that looks something like this:
Is it possible to change the default collation of SQL Server 2008 without having
I am creating a stored procedure in Sql Server 2008 database. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.