English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm writing a fake program for a store in my programming class. I'm stuck on one part though. I ask the user to input the
cost of and an item and if they have any coupons for it (and how much) then it computes the total after that. (easy stuff) But then i ask if they have any more items, and if they do, it repeats the "item cost / coupon amount" part. Where I'm getting stuck at is i can seem to find a way to be able to add up the total final cost (item - coupon). Every time the program starts over at "Input item cost:" i lose my numbers of the last item / coupon.

Any help with this?

** I dont know before hand how many items there will be total

** An example would be great as I'm still very new to programming

Thanks in advance =)

2007-10-12 19:57:21 · 1 answers · asked by Xan 1 in Education & Reference Homework Help

1 answers

I haven't programmed in Java in a few years, but conceptually, you could create an array to store values then add everything up.

Make an int x = 0, which would stand for the number of the item being cashed out (0 standing for the first item, 1 for the second, and so forth).

Then make an array a[], then make a[x] the final cost of the item. when you move onto the next item do x++ and it'll store the value of the next item in the next array slot.

When you're done with everything, run through the array with a for loop and add everything up.

2007-10-12 21:48:49 · answer #1 · answered by magicc001 2 · 0 1

fedest.com, questions and answers