# help with the do-wihle loop

Hello, I have been having a very hard time with this do while loop...it doesn't seem to work...it says cannot find symbol variable on the last line...can anybody help please?

thank you

System.out.print("Please tell me how many people you are in your group: ");
double numberPeople=input.nextDouble();
System.out.print("Thank you, now tell me the total cost of your meal: ");
double totalCost=input.nextDouble();
System.out.print("Thank you, now please tell me discount you were allotted in % form: ");
double discount=input.nextDouble();

//Compute the given data

do{
double worthDiscount=totalCost*(discount/100);//Calculate the total cost after the discount is given
double amountGst=worthDiscount*GST;//Calculate the amount of Pst (cost after disc.*.05)
double amountQst=(worthDiscount+amountGst)*QST;//Calculate the amount of Qst, so I did (cost after discount+Gst)*.075
double totalPayableAmount=worthDiscount+amountGst+amountQst;
double amountPaidByEach=totalPayableAmount/numberPeople;

//Output the results to console
System.out.println("Your discount is "+discount+"%, which comes up to "+worthDiscount+"\$.");
System.out.println("Your subtotal price after discount is "+(totalCost-worthDiscount));
System.out.println("You are "+numberPeople+ " people");
System.out.println("The GST comes to "+amountGst+" \$");
System.out.println("The Qst comes to "+amountQst+"\$");
System.out.println("The amount paid by each person is: "+(((((totalCost-worthDiscount)*1.05)*1.075))/numberPeople)+"\$");

System.out.println("Would you like to repeat the calculation?");
}

}

• Use comparison operator '==' instead of assignment operator '=', it will solve your problem.
thanks!
• Also declare answer if you haven't!
• Thanks for the help, but when I declare the variable before that, it says that the answer is already defined in main (java.lang.String).

import java.util.Scanner; //Import Scanner

public class Restaurant_Ass1
{

public static void main (String[]args)
{
//Create Scanner
Scanner input=new Scanner(System.in);

//ennumerate my constants
final double GST=0.05;
final double QST=0.075;

System.out.print("Please tell me how many people you are in your group: ");
double numberPeople=input.nextDouble();
System.out.print("Thank you, now tell me the total cost of your meal: ");
double totalCost=input.nextDouble();
System.out.print("Thank you, now please tell me discount you were allotted in % form: ");
double discount=input.nextDouble();

//Compute the given data

do{
double worthDiscount=totalCost*(discount/100);//Calculate the total cost after the discount is given
double amountGst=worthDiscount*GST;//Calculate the amount of Pst (cost after disc.*.05)
double amountQst=(worthDiscount+amountGst)*QST;//Calculate the amount of Qst, so I did (cost after discount+Gst)*.075
double totalPayableAmount=worthDiscount+amountGst+amountQst;
double amountPaidByEach=totalPayableAmount/numberPeople;

//Output the results to console
System.out.println("Your discount is "+discount+"%, which comes up to "+worthDiscount+"\$.");
System.out.println("Your subtotal price after discount is "+(totalCost-worthDiscount));
System.out.println("You are "+numberPeople+ " people");
System.out.println("The GST comes to "+amountGst+" \$");
System.out.println("The Qst comes to "+amountQst+"\$");
System.out.println("The amount paid by each person is: "+(((((totalCost-worthDiscount)*1.05)*1.075))/numberPeople)+"\$");

System.out.println("Would you like to repeat the calculation?");
}

}

}
• hmmmmm what are the exact outputs can you paste the error msgs?
• sorry! i haven't seen that you have already declared the answer before the closing '{' of do while ,just omit the double before the 'answer' variable inside while loop.
• i think its ok now take care!
• 1000 times, thank you!!
• This post has been deleted.
• This post has been deleted.
• What you told me works, but now there is another problem...I am trying to make this work... It is a problem where the user must enter an answer in order to restart or finish the program...when I use numbers, it works fine, (1 or 2) but when I use "y" or "n", there are errors that come out:

at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextDouble(Scanner.java:2387)
at Restaurant_Ass1.main(Restaurant_Ass1.java:54)

Process completed.

I know this must be a really simple thing, but I have no idea what, I have been trying everything, but it only works with numbers

import java.util.Scanner; //Import Scanner

public class Restaurant_Ass1
{

public static void main (String[]args)
{
//Create Scanner
Scanner input=new Scanner(System.in);

//ennumerate my constants
final double GST=0.05;
final double QST=0.075;

System.out.print("Please tell me how many people you are in your group: ");
double numberPeople=input.nextDouble();
System.out.print("Thank you, now tell me the total cost of your meal: ");
double totalCost=input.nextDouble();
System.out.print("Thank you, now please tell me the discount you were allotted in % form: ");
double discount=input.nextDouble();

//Compute the given dataSystem.out.printf("Total spendings: %5.2f",total);

double worthDiscount=totalCost*(discount/100);//Calculate the total cost after the discount is given
double amountGst=worthDiscount*GST;//Calculate the amount of Pst (cost after disc.*.05)
double amountQst=(worthDiscount+amountGst)*QST;//Calculate the amount of Qst, so I did (cost after discount+Gst)*.075
double totalPayableAmount=worthDiscount+amountGst+amountQst;// Calculate amount payable in total
double amountPaidByEach=totalPayableAmount/numberPeople;// Calculate amount paid by each member

//Output the results to console
",worthDiscount);
System.out.printf("Your subtotal price after discount is \$%5.2f
",(totalCost-worthDiscount));
System.out.printf("The GST comes to \$ %5.2f
",amountGst);
System.out.printf("The Qst comes to \$ %5.2f
",amountQst);
System.out.printf("Your total price is \$ %5.2f
",(((totalCost-worthDiscount)*1.05)*1.075));
System.out.printf("The amount paid by each person is \$ %5.2f
",(((((totalCost-worthDiscount)*1.05)*1.075))/numberPeople));

System.out.println("Would you like to repeat the calculation?");
{break;
}
{System.out.printf("I am sorry, but you input"+answer+"
This is not valid. Please try again.
");
}

}

}