Thread: how can i express

  1. #1
    Registered User mouse163's Avatar
    Join Date
    Dec 2002
    Posts
    49

    Unhappy how can i express

    Hello Everone.
    I hope somebody can 'pointer' me in the correct direction ...my problem is in char/ascii conversions
    i want to outpuit a Letter grade for an average that i have caluculated in the previous fx- but i am unsure if i need to call
    an "A" 65?. I will be returning this "grade" to a previous function that calls all of my calculations, and THEN drops them into their place in my struct. Hope that's enuf info...
    I am getting 2 types of errors on the following Fx syntax
    1.
    '<=' : unsafe use of type 'bool' in operation
    2.
    'A' : undeclared identifier

    Can someone perhaps tell me what is off about my expression?

    This is one teeny piece of a huge puzzle i am working on and i 'm finding myself kinda stuck and help is much appreciated...and hopefully when i have a little more mouse-experience i will be able to return the favor someday....
    Thx!
    Mouse

    Code:
    char CalcGrade(double AV){
    
    	{
    
    		if (90<= AV <= 100)
    			return  A;
    		else if (80<= AV <= 90)
    			return B;
    		else if (70<= AV <= 80)
    			return C;
    		else if (60<= AV <= 70)
    			return D;
    		else return F;
    	}
    
    }

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Do this:

    return 'A';

    instead of

    return A;
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Also your if expressions are incorrect, hence the unsafe bool warning.

    Try this, notice I've change some '<=' into '<'.

    Code:
    if (90 <= AV <= 100)
    return  'A';
    else if (80 <= AV < 90)
    return 'B';
    else if (70 <= AV < 80)
    return 'C';
    else if (60 <= AV < 70)
    return 'D';
    else return 'F';
    You should note that if it is possible for someone to be given 101%, your function is going to assign them an 'F'.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: how can i express

    Code:
    char CalcGrade(double AV)
    {
       if(AV >= 90) return 'A';
       if(AV >= 80) return 'B';
       if(AV >= 70) return 'C';
       if(AV >= 60) return 'D';
       return 'F';
    }

  5. #5
    Registered User mouse163's Avatar
    Join Date
    Dec 2002
    Posts
    49

    Thumbs up thanks alot guys!!

    thanks so much...it's the little things that make the BIG Picture clearer!!
    MUCH appreciated!
    Mouse

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Davros
    Also your if expressions are incorrect, hence the unsafe bool warning.

    Try this, notice I've change some '<=' into '<'.

    Code:
    if (90 <= AV <= 100)
    return  'A';
    else if (80 <= AV < 90)
    return 'B';
    else if (70 <= AV < 80)
    return 'C';
    else if (60 <= AV < 70)
    return 'D';
    else return 'F';
    You should note that if it is possible for someone to be given 101%, your function is going to assign them an 'F'.

    Nonononononono!!! You can't string logical comparisons together like that!

    For example

    90 <= AV <= 100

    Won't check if AV is between 90 and 100

    A logical operator like <= returns a boolean value (true or false).

    So in actuality, what

    90 <= AV <= 100

    does is

    90 <= AV

    that will return either 1 or 0

    then, it will compare that 1 or 0 with 100

    So if AV was greater than or equal to 90 it would return 1, and then it would do

    1 <= 100 which would return true.

    Since the first expression would return either 1 or 0 the expression would always be true.

    What you really want to do is make 2 separate comparisons and connect them with &&

    like

    if( 90 <= AV && AV <= 100 )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# express vs C++ express
    By RocketMan in forum C# Programming
    Replies: 16
    Last Post: 12-15-2008, 04:05 PM
  2. VC++ Express Edition
    By alyeska in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2007, 09:08 PM
  3. Linker errors with 2005 Express
    By thetinman in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2006, 09:04 AM
  4. Visual Studio Express for free
    By Frobozz in forum C# Programming
    Replies: 2
    Last Post: 04-29-2006, 09:59 PM
  5. Familar with Outlook Express?
    By Shadow in forum Tech Board
    Replies: 1
    Last Post: 05-22-2004, 01:45 PM