Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with "else without if" error

843789May 14 2010 — edited May 15 2010
I'm a student, new to Java; this is an assignment I am trying to complete.

I have been provided with a data file to read from:

40 Light Karen L
81 Fagan Bert Todd
60 Antrim Forrest N
95 Camden Warren
52 Mulicka Al B
89 Lee Phoebe
75 Bright Harry
92 Garris Ted
43 Benson Martyne
100 Lloyd Jeanine D
73 Leslie Bennie A
70 Brandt Leslie
89 Schulman David
90 Worthington Dan
70 Hall Gus W

The instructions are to read the values and output a message dependent on the name's corresponding grade.

I am receive the error at this point:
else
{
msg = "FAILING";
}

here is my full code:

//*****************************************
import java.io.*;
import java.util.*;

public class prgrm8

{ public static void main(String [] args) throws Exception
{ Scanner inFile = new Scanner(newFileReader ("prgrm8.dat"));
PrintWriter outFile = new PrintWriter("prgrm8.out");
int value, ctr = 0, ctrR = 0;
double sum = 0 ;
String filename = "prgrm8.dat";
StringTokenizer st;
outFile.println("REPORT");
while(inFile.hasNext())
line = inFile.nextLine();
st = new StringTokenizer (line);
value = Integer.parseInt(st.nextToken());
name = st.NextToken();
while(st.hasMoreTokens())
name = name + " " + st.nextToken();
ctr++;
if(value >= 90)
{
msg = "OUTSTANDING";
}
else if (value >= 70)
{
msg = "Satisfactory";
}
sum += value;
ctrR++;
else
{
msg = "FAILING";
}

outFile.println(value + " " + name + " " + msg);
outFile.println(ctr + " " + "processed names");
outFile.println(ctrR + " " + "between 70 and 89 inclusive");
if(ctrR = 0)
outFile.close();
} //end
}

Edited by: Max_Quattromani on May 13, 2010 9:24 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2010
Added on May 14 2010
9 comments
254 views