+ 2

Java Cachier - use local variable outside of the loop(or nest it?)

Hi guys! I working on the program that simulates a cashier terminal. I need to use FOR loop to ask user three times about quantity of each of 3 items. Program is ready, but I have a problem with printing GRAND TOTAL because I can't figure out how to use a sub_totals from loops outside of the loop. Yes, I'm noobie) Please help) https://code.sololearn.com/ckhExauxFaBS

1st Feb 2018, 4:40 PM
DIY Mods
DIY Mods - avatar
8 Antworten
+ 1
Ok. The problem actually was in name of local variables, not in their position, because I already used them outside of the loop. Here is the good code https://code.sololearn.com/cLOL3QOAFhN9 If anybody knows how to make one loop from this 3, I would really appreciate your contribution
1st Feb 2018, 6:54 PM
DIY Mods
DIY Mods - avatar
+ 1
your sub_j and so on are declared inside the for loops but u trying to use them outside
1st Feb 2018, 5:14 PM
Jeremy
Jeremy - avatar
0
That's what I did. It doesn't work
1st Feb 2018, 4:56 PM
DIY Mods
DIY Mods - avatar
0
Hi, Jeremy!) Good to see you! How can I fix it? Where to move them?
1st Feb 2018, 5:16 PM
DIY Mods
DIY Mods - avatar
0
do what ace said, declare them outside of the loops
1st Feb 2018, 5:25 PM
Jeremy
Jeremy - avatar
0
I did. Look at my code. I tried both ways. Total comes incorrect
1st Feb 2018, 5:29 PM
DIY Mods
DIY Mods - avatar