+ 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
8 Réponses
+ 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
+ 1
your sub_j and so on are declared inside the for loops but u trying to use them outside
0
That's what I did. It doesn't work
0
Hi, Jeremy!) Good to see you! How can I fix it? Where to move them?
0
do what ace said, declare them outside of the loops
0
I did. Look at my code. I tried both ways. Total comes incorrect