• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error checking code - Need help - Please!!

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael,
Thanks again! I'll go see what I can do with it now. You are one smart guy!!!
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic