I have to make a program for school that asks the user to input the amount of items they want, and their respective price. After that they have to input the GST, QST ( well taxes.) and the program has to calculate the subtotal and total.
I'm having a little issue. My program has to calculate how many errors the user "creates" by inputting wrong values. I hit a wall when I had to code the "ask for the price of each item". I tried a for loop, but eclipse terminates the program before it gets to the for loop ( for no apparent reason, so it must be a logic error, right?) Anyway here's where I'm at:
import java.util.Scanner;
public class ItemCost {
public static void main(String[] args) {
int i = 1;
int items, d, item;
double gst, qst, subt, Tot, PriceItems;
Scanner x = new Scanner(System.in);
Scanner y = new Scanner(System.in);
System.out.println("Please input the amount of items bought");
items = x.nextInt();
while (items < 1 || items > 10) {
System.out.print("Sorry the input was not correct, please try again\n");
items = x.nextInt();
i++;
}
for (item = 1; item == items; item++) {
System.out.println("Please input the price of" + item);
PriceItems = y.nextDouble();
}
}
}
Aucun commentaire:
Enregistrer un commentaire