Hi there. This is actually one of my assignment and i am having problem with the do while sentinel looping. The result i get is totally inverse from the one i expected. The system is supposingly ended when user enter 0, but it ended when user enter any value but the looping continue when user enter 0.

These are the code. Thank you.Sorry i am still very new in programming. =(

import java.util.Scanner;
public class SoftwareWorkshop   {
    public static void main(String[] args)  {
        Scanner input = new Scanner(System.in);
        int Registrant, totalRegistrant;
        double Charges, totalCharges, averageCharges, totalAll;
        totalRegistrant = 0;
        totalAll = 0;
        Registrant =0; 
        do  {
        System.out.println("Enter amount of registrant in the company.Enter 0 to end the system.");
        Registrant = input.nextInt();
            if (Registrant >=11)    {
            Charges = 250;
            totalCharges = (Registrant * Charges);
            totalRegistrant += Registrant;
            totalAll += totalCharges;
            System.out.println("The total is RM" + totalCharges);
            }
            else if (Registrant >= 6)   {
            Charges = 400;
            totalCharges = (Registrant * Charges);
            totalRegistrant += Registrant;
            totalAll += totalCharges;
            System.out.println("The total is RM" + totalCharges);
            }
            else {
            Charges = 450;
            totalCharges = (Registrant * Charges);
            totalRegistrant += Registrant;
            totalAll += totalCharges;
            System.out.println("The total is RM" + totalCharges);
            }
        }

        while(Registrant == 0); {
        System.out.println("End");
        }
    }

}

Edited 3 Years Ago by Nick Evan: Fixed formatting

You have

do {
   ...
while(Registrant == 0);

ie keep doing the loop as long as Registrant is 0
Can you see why that's wrong?

One thing that you will learn about computers is that they will always do exactly what you tell them to do. ...even when that's not what you want.

So you've asked the computer to continue doing the loop while the Registrant (number) is equal to zero.

Is that what you really want? :-/

oh ok bro! thank you i get it now! sorry for the newbie question. thanks for the answer! love ya guys.

This question has already been answered. Start a new discussion instead.