Jump to content

Representing money and keeping track

Recommended Posts

Hello  All I am working on a application where I have to represent money and display how many bills were used to make each amount. I can do this The only problem I am working on figuring out is recording the number of each bill that has been used and to subtract it for the current number. I was thinking of making a money class for 100s 50s 20s 10s 5s and 1s but  I cant have each value bill with a specified number of how many. Having the value specificed I would have this : but each one of these has no value amount

	     int hund = 10;
	            int fif = 10;
	            int twen = 10;
	            int ten = 10;
	            int five = 10;
	            int one = 10;

Or if I want a value amount I was thinking this But I cant determine a fixed number to use

	    public class Money
	        public int HundBill { get; set; }
	        public int FiftBill { get; set; }
	        public int TwentBill { get; set; }
	        public int TenBill { get; set; }
	        public int FiveBill { get; set; }
	        public int OneBill { get; set; }
	        public Money()
	            HundredDollarBill = cash / 100;
	            cash %= 100;
	            FiftyDollarBill = cash / 50;
	            cash %= 50;
	            TwentyDollarBill = cash / 20;
	            cash %= 20;
	            TenDollarBill = cash / 10;
	            cash %= 10;
	            FiftyDollarBill = cash / 5;
	            cash %= 5;
	            OneDollarBill = cash / 1;
	            cash %= 1;      }

I am getting the users input and Ill get a number and I want to minus the number of bills that were used to make that amount and to keep track.

Share this post

Link to post
Share on other sites

Instead of separate variables, use an array whose key is the face value of the bill and the array values are the quantities. The amount for each type of bill would be the key * qty.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.