The output of my code is completely skipping over the if statements under the while statement. Not sure what the issue is here. I've spent some time on this forum looking for the answer and so I've tweaked the "veteran == y/n" to "veteran = y/n" but that hasn't resolved the problem.(Java)
import java.util.Scanner;
public class ch4{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("\nTICKET PRICES PER PERSON: ");
System.out.println("Ages 13 to 64: $17.99");
System.out.println("Ages under 13: $9.99");
System.out.println("Ages 64 and up: $9.99");
System.out.println("Military service: $7.99");
System.out.println("Senior veterans: $4.99");
double normalPrice = 17.99;
double kidsPrice = 9.99;
double seniorsPrice = 9.99;
double soldiersPrice = 7.99;
double veteransPrice = 4.99;
System.out.print("\nHow many tickets would you like? ");
int tickets = input.nextInt();
int counter = 1;
double total = 0.0;
System.out.println();
while (counter <= tickets) {
System.out.print("\nEnter age of the patron: ");
int age = input.nextInt();
System.out.print("\nMilitary service? type y/n: ");
String veteran = input.next();
System.out.println();
if (age >= 13 && age <= 64 && veteran = "n") {
total = total + normalPrice;
}
if (age < 13 && veteran = "n") {
total = total + kidsPrice;
}
if (age > 64 && veteran = "n") {
total = total + seniorsPrice;
}
if (age >= 13 && age <= 64 && veteran = "y") {
total = total + soldiersPrice;
}
if (age > 64 && veteran = "y") {
total = total + veteransPrice;
}
counter++;
}
System.out.printf("%nTotal price is $%.2f" , total);
}
}
Aucun commentaire:
Enregistrer un commentaire