permaculture playing cards*
The moose likes Beginning Java and the fly likes Error checking code - Need help - Please!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error checking code - Need help - Please!!" Watch "Error checking code - Need help - Please!!" New topic
Author

Error checking code - Need help - Please!!

Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Ok guys, what am I doing wrong? Again...
I am trying to put an error checking code into my program so if a user enters anything above a 10, it will give them a message to re-enter their quiz score. I have it half way working, and it does bring up the error message if they enter something over 10, but it also brings up the same message if they enter something under 10, which it should do. Any suggestions would be greatly appreciated?
Here a snippet of my code so far..
________________________________________________________________________

System.out.print("Please enter your name: ");
String name = SavitchIn.readLine();

System.out.print("\nPlease enter your first quiz grade: ");
quiz1 = SavitchIn.readLineInt();

System.out.print("\nPlease enter your second quiz grade: ");
quiz2 = SavitchIn.readLineInt();

if ((quiz1 > 10) || (quiz2 > 10));

{ //Error checking, Try again, code.

System.out.println("The quiz score you entered is too high.");
System.out.println("Quiz scores must be between 0 - 10");
System.out.println("Please re-enter your quiz score.");
System.out.print("\nPlease enter your first quiz grade: ");
quiz1 = SavitchIn.readLineInt();
System.out.print("\nPlease enter your second quiz grade: ");
quiz2 = SavitchIn.readLineInt();

//I tried putting an else statment right here, but it kept telling me
//I was missing an If statement, so who knows?

System.out.print("\nPlease enter your midterm exam: ");
midtermExam = SavitchIn.readLineInt();
System.out.print("\nPlease enter your final exam score: ");
finalExam = SavitchIn.readLineInt();
}
_____________________________________________________________

I'd appreciate any information you can give me. Thanks!!!


) ) ) )
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
I meant to say it should NOT bring up the error message if they enter the correct numbers 1 thru 10. Heck I cant even type right half the time. Ha.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
your problem is the semi-colon at the end of this line
if ((quiz1 > 10) || (quiz2 > 10));

but you want to look at creating some type of loop for this.
your code handles one error situation, what if the user types the wrong info twice?

here's one way (not the best way, but it's simple)

Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Michael,
Thanks again! I'll go see what I can do with it now. You are one smart guy!!!
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Hi Michael,

You're one smart dude. It took me forever to figure out exactly where I should put that code, but I finally got it where it should be. I surely hope one day I can be as good as you are!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error checking code - Need help - Please!!