0

I am in a programming class and we are making a simple program. In this program the user will put in five assignments, the points they got on that assignment and the total points available. I have all of the basic things except for a grading scale. I am trying to make it so when their percent is between 92 and 100 percent it will say you have an A in this class. This is what I have so far:

if ( pC >= 92, pC <= 100 ) {
    System.out.print("\n You have an B");
}

So far that has not worked and I am having a lot of trouble.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Crimson
  • 23
  • 1
  • 1
  • 3

2 Answers2

3

What you're trying to do is check if a number is >= 92 AND <= 100. That isn't done with a comma, like you have:

if ( pC >= 92, pC <= 100 ) {
    System.out.print("\n You have an B");
}

Rather, the AND operator is && (and you said you want this range to be an A, rather than a B), which means your code would look like this:

if ( pC >= 92 && pC <= 100 ) {
    System.out.print("\n You have an A");
}
Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
  • I have only been in this class for about a week. I thought it was JavaScript i guess I know better now. Thank you for the answer, I will have to try it when I get back. And that B was supposed to be an A. I got the comma from another question on here and they said it would work. But again thank you very much. – Crimson Feb 26 '15 at 21:22
  • There may be some other programming language which uses commas to represent an AND operator - but yeah, in Java it's `&&`. Good luck! – Sam Hanley Feb 26 '15 at 21:23
0

I think what you are looking for is this:

If the point is between 92% and 100%:

if ( pC >= 92 && pC <= 100 ) {
    System.out.print("\n You have an A");
}

If the point is out that range:

if ( pC < 92 ) {
    System.out.print("\n You have an B");
}

Or, to the complete statement, you will want to make:

if ( pC >= 92 && pC <= 100 ) {
  System.out.print("\n You have an A");
}
else if ( pC < 92 ){
  System.out.print("\n You have an B");
}
else {
  System.out.print("\n You have a point out of the curve");
}
Laerte
  • 7,013
  • 3
  • 32
  • 50