hi i need to write a program that collects bottle caps. this program is supposed to collect all 5 bottle caps with the letters BASIC. Each letter has a ratio of being found...B-20% A-20% S-40% I-19% C-1%..... i want to use math.random...the range of it i want is 1-100...i made if statements..the first 20 is b, next 20 is A, next 40 is S next 19 is I and the last one is C.... the program is supposed to print out the number of bottle caps needed to get all 5 to win a prise and the number of each kind. now the following code compiles, but when i run it it does not work. would i rather need a random class? pls help
Hmmm... so what does the program do when it "does not work"? Print an error message? Print anything at all? You can always add some print statements for debugging purposes to figure out what's going on. E.g.
By studying the output of statements like this, you can get more information about what your program is actually doing. Is it what you expect? How is it different? When you get to a part of the program which behavaes differently than you expect, you can add additional print statements to get more info than I've provided so far. If the results still don't make sense to you, post here describing what sort of results you're getting. Hope that helps...
Without looking too deeply at your code, the first thing I see is that your loop will only run once. The reason is that - according to your 'if' conditional, the loop only runs AS LONG AS ALL letters == 0. Once you increment a letter ( which should be done B += 1 ), you make this statement false, so the loop stops executing. Does that help?
-nothing important to say, but learnin' plenty-