Help, I cannot work out how to get my loop to continue until the user enters in 0.

If the user enters 1 then the loop needs to continue until there is no more groups to enter which is the point the user enters a 0

import java.util.Scanner;
public class ZooEntryCharge {

    public static void main(String[] args) {
    	//assign value
    	int GroupValue = 0;
    	// Create a scanner
    	Scanner input = new Scanner(System.in);

    	do {
    		// prompt for user input
    		System.out.print("Enter a group y = 1 or n = 0 ");
    		int intGroupValue = input.nextInt();

    		System.out.print("Enter number of children age under 5 ");
    		int intUnderFiveValue = input.nextInt();

    		System.out.print("Enter the number of children accompanied by an adult aged from 6 to 15 years old ");
    		int intAccompaniedChildValue = input.nextInt();

    		System.out.print("Enter the number of unaccompanied by an adult aged from 6 to 15 years old ");
    		int intUnaccompaniedChildValue = input.nextInt();

    		System.out.print("Enter the number of adults from 16 to 59 years old ");
    		int intAdultValue = input.nextInt();

    		System.out.print("Enter the number of seniors aged 60 and older ");
    		int intSeniorsValue = input.nextInt();
    		// reads value and prints out
    		int Value = intUnderFiveValue + intAccompaniedChildValue + intUnaccompaniedChildValue + intAdultValue + intSeniorsValue;
    		System.out.println ("Total amount of people in the group is " + Value );

// end loop if group value is not 1

    	}while (GroupValue != 0);

    	total = Value + Value;

    	System.out.println("The total number of groups is " + total);

Thank-you for your help

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

8 Years
Discussion Span
Last Post by stultuske
int intGroupValue = input.nextInt();

drop this line and replace it by

GroupValue = input.nextInt();

2 recommandations, though.
in Java, there is a naming convention, which makes it easier to determine whether something is a class or a variable. you might want to follow this, by renaming 'GroupValue' into 'groupValue'
secondly, it's easier for you to read and maintain, if you place the line in which you ask for the new input, directly above the end of the loop, like this:

// rest of your code
GroupValue = input.nextInt();
}while (GroupValue != 0);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.