Error: "warning: character constant too long for its type"

This is my first post so bear with me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
char Grade(int avg, int& aCount, int& bCount, int& cCount, int& dCount, int& fCount)
{
  switch(avg)
  {
    case '0 ... 59' : return 'F';
    break;
    case '60 ... 69' : return 'D';
    break;
    case '70 ... 79' : return 'C';
    break;
    case '80 ... 89' : return 'B';
    break;
    case '90 ... 100' : return 'A';
    break;
  }
}


I'm getting the error in this chunk of code. I think it has something to do with how I formatted my switch statement, but I'm not sure.

Ignore all the counters posted as parameters up there. I am going to add them as counters under each grade but I get the same error whether or not they are used in the body of the function.

Any help?

Thanks a ton.
Last edited on
This isn't formatted as per C++. So yes, you will get an error:
'0 ... 59' is invalid C++, it does not mean "0 to fifty nine". would mean a character with the code 0 ... 59 which is a completely invalid character.

What you want will be this:
1
2
3
4
5
6
7
8
char Grade(int avg)
{
  if (avg < 60)  return 'F';
  if (avg < 70)  return 'D';
  if (avg < 80)  return 'C';
  if (avg < 90)  return 'B';
  return 'A';
}
closed account (3qX21hU5)
Just curious the reason why you don't need if else is because it will just go down the line and doesn't matter if the other ones after it might qualify because it has already returned?
Topic archived. No new replies allowed.