Developer's Blog
Register Low Fi Mark Forums Read

Notices

Reply
 
Thread Tools
Old 04-27-2012, 10:25 AM   #1
Nozumu
Member
 
Nozumu's Avatar
 
Join Date: Sep 2011
Posts: 94
Nozumu is offline

Default How should this program flow?


Hey guys, I'm having some trouble with this program. The program should work like this

[1] It asks the user to input 3 data, # of records, total quantity and total cost

[2] From an existing database (with ID, recordname, price) it will select random records until it has achieved the number of records inputted by the user (records already picked can be picked again)

[3] each selected record is then paired with a random quantity, the sum of all the quantities shall be equal to the amount inputted by the user

[4] the price is multiplied by the amount paired to the record and will be the cost, the sum of all the cost should be equal to the one inputted by the user.

So that's it. I have tried so many times but to no avail. I don't need codes, I just need someone to guide me on how the program should flow for it to work.
  Reply With Quote
Old 04-27-2012, 02:42 PM   #2
XaTrIxX
Forum Staff
 
XaTrIxX's Avatar
 
Join Date: Jun 2009
Posts: 3,324
Blog Entries: 3
XaTrIxX is offline
Default Re: How should this program flow?

I'd say, partially it depends on the programming language used, but generally I'd start off with designing DAOs (Data Access Objects), which provide basic database queries. I guess you won't really need much more than the record select.

You then have the layer which receives this result and does your calculations. Save your result Record in a class and work with a list of (for example) RecordClasses then.

It's important to abstract layers. You can code each of them individually and put them together after, or whatever way you like, but assure one layer works (maybe with Tests).

Let me know if that helped you!
__________________

Programming section moderator.
Also resolving issues in Marketplace section.
Playing DotA since 2005.
  Reply With Quote
Old 04-28-2012, 05:35 AM   #3
Nozumu
Member
 
Nozumu's Avatar
 
Join Date: Sep 2011
Posts: 94
Nozumu is offline
Default Re: How should this program flow?

Quote:
Originally Posted by XaTrIxX View Post
I'd say, partially it depends on the programming language used, but generally I'd start off with designing DAOs (Data Access Objects), which provide basic database queries. I guess you won't really need much more than the record select.

You then have the layer which receives this result and does your calculations. Save your result Record in a class and work with a list of (for example) RecordClasses then.

It's important to abstract layers. You can code each of them individually and put them together after, or whatever way you like, but assure one layer works (maybe with Tests).

Let me know if that helped you!
It did, thanks! Now I'm having problems with the conditions. As of now it can select the records and generate the numbers which sums up to the number by the user, my problem is i have no idea on how to make the total costs equal to the input.
  Reply With Quote
Old 04-29-2012, 11:42 AM   #4
XaTrIxX
Forum Staff
 
XaTrIxX's Avatar
 
Join Date: Jun 2009
Posts: 3,324
Blog Entries: 3
XaTrIxX is offline
Default Re: How should this program flow?

I'm not sure if i understood correctly, but you have to sum up to a certain value?

This depends on how well distributed your values are, e.g. if your values make it possible, sum up as long as you get over your value, then remove a value to get to the exact sum, or remove to get lower and add another one to sum it up.

I hope this helps, but maybe i misunderstood totally.
__________________

Programming section moderator.
Also resolving issues in Marketplace section.
Playing DotA since 2005.
  Reply With Quote
Old 04-29-2012, 12:04 PM   #5
Nozumu
Member
 
Nozumu's Avatar
 
Join Date: Sep 2011
Posts: 94
Nozumu is offline
Default Re: How should this program flow?

Let's say that I input the following:

# Records: 5
Quantity: 15
Total Cost: 800

Then It should Output something like this: (Record Name and Price is from a database while Quantity is randomly generated)

RECORD NAMEPRICEQUANTITYCOST
PlayDotA753225
XaTrixX1002200
PlayDotA75175
Francis504200
Shatterman205100
TOTAL 15800

As of now the random selection of records and quantity works, but I have no idea on how to make the total cost equal up too. Will looping the quantity randomization work or will it just make an endless loop? Does it have to use a really complex selection system or what?
  Reply With Quote
Old 04-29-2012, 10:39 PM   #6
XaTrIxX
Forum Staff
 
XaTrIxX's Avatar
 
Join Date: Jun 2009
Posts: 3,324
Blog Entries: 3
XaTrIxX is offline
Default Re: How should this program flow?

I described a way of doing it. Randomization loop will work also if you have a half-decent random function!
__________________

Programming section moderator.
Also resolving issues in Marketplace section.
Playing DotA since 2005.
  Reply With Quote
Reply
  Entertainment Programming


Forum Jump

Thread Tools