alright iam working on this code and it is driving me nuts someone please help me alright here is my code :

import java.util.Scanner;

public class TestScoreApp
{
    public static void main(String[] args)
    {
        // display operational messages
        System.out.println("Please enter test scores that range from 0 to 100.");
        System.out.println("To end the program enter 999.");
        System.out.println();  // print a blank line

        // initialize variables and create a Scanner object
        double scoreTotal = 0;
        int scoreCount = 0;
        int testScore = 0;
        Scanner sc = new Scanner(System.in);

    	// get a series of test scores from the user
        while (testScore > 100)
        {
		    // get the input from the user
            System.out.print("Enter score: ");
        	testScore = sc.nextInt();

        	// accumulate score count and score total
        	if ( testScore < 0 || testScore > 100 )  // invalid scores  
               {  
                 System.out.println( "Invalid entry" );  
 }  


        	{
        		scoreCount = scoreCount + 1;
        		scoreTotal = scoreTotal + testScore;
			}
		}

    	// display the score count, score total, and average score
    	double averageScore = scoreTotal / scoreCount;
    	String message = "\n" +
    	                 "Score count:   " + scoreCount + "\n"
    	               + "Score total:   " + scoreTotal + "\n"
		               + "Average score: " + averageScore + "\n";
		System.out.println(message);
	}
}

my problem is the code runs and works but it never displays the proper error message after entering a score that is higher than 100, however 999 isthe ender so has to stop when thats entered how do i make this work please help me =]

Recommended Answers

All 5 Replies

testScore = 0
 and then 
while(testScore>100)
then execute loop

If testScore is zero how can it execute the loop..
Hope this help

kinda helps my friend tried helping me this is what if got to so far :

import java.util.Scanner;

public class TestScoreApp
{
    public static void main(String[] args)
    {
        // display operational messages
        System.out.println("Please enter test scores that range from 0 to 100.");
        System.out.println("To end the program enter 999.");
        System.out.println();  // print a blank line

        // initialize variables and create a Scanner object
        double scoreTotal = 0;
        int scoreCount = 0;
        int testScore = 0;
        Scanner sc = new Scanner(System.in);

    	// get a series of test scores from the user
        while (testScore<=100)
        
		    // get the input from the user
            System.out.print("Enter score: ");
        	testScore = sc.nextInt();

        	// accumulate score count and score total
        	if ( testScore == 999 ) // invalid scores
        	{
        		
        	}
        	
        	else if (testScore >=0 && testScore <=100)
              
        	{
        	}
        	else System.out.println( "Invalid entry" );  
        	}

               scoreCount = scoreCount + 1;
        	   scoreTotal = scoreTotal + testScore; 
    }
		

    	// display the score count, score total, and average score
    	double averageScore = scoreTotal / scoreCount;
    	String message = "\n" +
    	                 "Score count:   " + scoreCount + "\n"
    	               + "Score total:   " + scoreTotal + "\n"
		               + "Average score: " + averageScore + "\n";
		System.out.println(message);
	}
}

now when i run it entering 999 off the bat ends it like it should, but if i enter say 125 it should show the error message its not workin my friend messed with it tryin to help

Member Avatar for hfx642

Well...
Your "while" loop is NOT a loop.
You're missing your parenthesis.

can you give me an example ?? this damn code been driving me nuts the past weeks

Member Avatar for hfx642

Well... You did have your parenthsis in your first posting,
but you took them out in your second posting.

2. What you mean to say is that if the test_score <= 100 OR!!! test_score = 999???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.