Results 1 to 4 of 4
  1. #1
    Gagnrath is offline Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Default Stuck on error message

    I am trying to work on a tutorial in my Java book and I got stuck on a piece of the programming.

    What this is supposed to do is test scores entered between 0-100 are counted and inputted into a variable. This works. The next part is that any number outside of that range prompts an error message and should return to the prompt to allow further scores to be entered. This is where it is broken. The last piece is that the number 999 is the specific key to tell the program to average the scores and display the it. This works. So what I am hoping someone might be able to help me with the second part as everything I have tried has failed and I figure a fresh set of eyes may be able to spot where I am going wrong.

    I have been running this code in netbeans

    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 <= 100)
    {
    scoreCount = scoreCount + 1;
    scoreTotal = scoreTotal + testScore;
    }


    Java Code:
    else if (testScore == 999) 
                {
                    scoreCount = scoreCount + 0;
                }
    
     
                else if (testScore > 100) 
                {
                    System.out.println("Invalid Number, Please Try Again");
                }
    }

    // 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);
    }
    }
    Last edited by Gagnrath; 06-20-2013 at 03:45 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Stuck on error message

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Gagnrath is offline Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Default Re: Stuck on error message

    Made appropriate changes

  4. #4
    Gagnrath is offline Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Default Re: Stuck on error message

    So as it turns out, I was missing a couple of syntax pieces that I had yet to learn in my text.

    Great little website that helped was this:

    Summary of Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Stuck on a Do While logical error
    By dougie1809 in forum New To Java
    Replies: 8
    Last Post: 01-23-2012, 05:05 PM
  2. Need help with error message!
    By cstampar in forum New To Java
    Replies: 2
    Last Post: 12-04-2011, 07:52 PM
  3. error message
    By tri.yudhanto in forum JDBC
    Replies: 0
    Last Post: 01-13-2011, 01:20 PM
  4. Stuck on an error
    By Peril in forum Advanced Java
    Replies: 3
    Last Post: 03-23-2010, 06:34 AM
  5. stuck on same syntax error....
    By Moltisanti in forum New To Java
    Replies: 2
    Last Post: 09-01-2009, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •