exceedinglife Posted February 9, 2019 Share Posted February 9, 2019 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 9, 2019 Share Posted February 9, 2019 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.