I am using a do-while loop that loops based on the input of the user as a 'Y' or 'N'. If the user chooses to continue by pressing 'Y' or 1 (for simplicity), on the second iteration it skips the first input in the same loop.
do{
System.out.println("Enter the location: ");
cartItem.purchaseLocation = input.nextLine(); // This input is skipped on second iteration
System.out.println("Enter the product description: ");
cartItem.productDescription = input.nextLine();
System.out.println("Enter the price of the item: ");
cartItem.productPrice = input.nextDouble();
System.out.println("Enter the quantity: ");
cartItem.quantity = input.nextInt();
cartList.add(cartItem);
System.out.println("Do you want to add more items ? y = 1 / n = 0: ");
exitVar = input.nextInt();
}while(exitVar!=0); // Repeat till no more items need to be added in the cart
So when the user presses input 0 to repeat the procedure, the line
cartItem.purchaseLocation = input.nextLine();
which is the very first input in the loop will be skipped. Any suggestions what might be wrong here ?