Results 1 to 3 of 3
  1. #1
    Twixmaster123 is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Angry Grade averaging program issue!

    So my issue is that after creating the program that takes 10 numbers that the user enters and averages them together, I decided to get bold and add a if else statement as shown below. Now before I added the if else statement the program worked correctly, taking 10 numbers and averaging them together. Now, after adding the if else statement it only allows the user to enter 1 number and then averages it? I am a bit confused as to why this is happening, I am sure I made a small mistake somewhere along the lines. Thanks to anyone who can clear this up for me!
    Java Code:
    import java.util.Scanner; //importing the scanner utility
    
    class apples{ //class is apples (irrelevant to problem)
    	public static void main (String args[]){
    		Scanner input = new Scanner(System.in); //starting the scanner for the keyboard
    		int total = 0; //holds the sum of the grades
    		int grade; //input numbers
    		int average; //average the grades
    		int counter = 0; //counter for while loop
    
    		while (counter < 10){ //counter is less than 10 numbers
    			grade = input.nextInt(); //numbers stored temporarily in grade
    			total = total + grade; //keeps a running tally of all the grades entered 
    			counter++;
    			
    		average = total/10; //averages the total of the 10 numbers
    		System.out.println("Your average is " +average); //Prints the average
    		
    		if (average < 70){
    			System.out.println("You failed! ;("); //if average of the 10 numbers is less than 70 you fail
    		}
    		else
    			System.out.println("You passed! ;)"); //if average of the 10 numbers is more than 70 you pass
    		}
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,458
    Blog Entries
    7
    Rep Power
    20

    Default Re: Grade averaging program issue!

    Shouldn't there be a right curly bracket at line #14? (the indentation suggests so) Now you're calculating the average in the body of the while loop and there aren't ten numbers entered yet.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Twixmaster123 is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default Re: Grade averaging program issue!

    Oh duh! Thank you so much I fixed the problem!

Similar Threads

  1. Java PI program issue
    By Darin in forum New To Java
    Replies: 6
    Last Post: 03-20-2012, 01:12 AM
  2. Replies: 7
    Last Post: 01-20-2012, 09:44 PM
  3. help with program!! looping issue?
    By zombian in forum New To Java
    Replies: 6
    Last Post: 11-21-2010, 10:14 PM
  4. Program Issue
    By coder09 in forum New To Java
    Replies: 5
    Last Post: 01-27-2009, 01:36 AM
  5. Replies: 1
    Last Post: 11-14-2008, 06:56 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
  •