Results 1 to 3 of 3
Thread: Grade averaging program issue!
- 04-07-2012, 07:29 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
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 } } }
- 04-07-2012, 09:42 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-07-2012, 05:44 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Java PI program issue
By Darin in forum New To JavaReplies: 6Last Post: 03-20-2012, 01:12 AM -
Having trouble with simple grade averages/raised averages program
By LogicalOutlier in forum New To JavaReplies: 7Last Post: 01-20-2012, 09:44 PM -
help with program!! looping issue?
By zombian in forum New To JavaReplies: 6Last Post: 11-21-2010, 10:14 PM -
Program Issue
By coder09 in forum New To JavaReplies: 5Last Post: 01-27-2009, 01:36 AM -
[SOLVED] Issue with Using Runtime.exec to run an external program
By coolFrenzi in forum Advanced JavaReplies: 1Last Post: 11-14-2008, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks