I want to make a program that asks the user to enter how many laptops they want to buy, then ask them if the laptops have different prices. if the answer is "yes", it's gonna repeat the question based on the laptop's quantity. Otherwise it'll just ask once and then calculate the cost of the laptop/s
I get this:
How many laptops do you want to buy? 3
Do they have different price (yes/no)? Enter laptop/s price:
import java.util.Scanner;
public class LaptopCostCalculatorV2 {
public static void main(String[] args) {
int laptopsPrice = 0;
int laptopQuantity;
Scanner scan = new Scanner(System.in);
System.out.print("How many laptops do you want to buy? ");
laptopQuantity = scan.nextInt();
System.out.print("Do they have different price (yes/no)? ");
String choose = scan.nextLine();
if (choose.equals("yes")) {
for (int i = 0; i < laptopQuantity; i++) {
System.out.println("Enter laptop price");
laptopsPrice = scan.nextInt();
}
} else {
System.out.println("Enter laptop/s price: ");
int laptopPrice = scan.nextInt();
}
}
}
Why does it not let me enter the answer to the second question?