Thread: Returning a string in a function

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    22

    Returning a string in a function

    I am writing a function which passes a score and returns a letter grade based on the score. Real simple stuff. However I cannot seem to understand what to do with a score that is less than 0 or greater than 100. In this case I would like to return an invalid statement but I cannot figure out how.

    Basically I have it set up in a series of if-else if - else statements.

    this is my final else statement

    Code:
     
    else
            letter_grade = 'invalid' ;
    and letter_grade is of type char.
    How can I pass 'invalid'

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Return a 0

    The function can then say "if not 0, then..."
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    or designate a single letter to mean invalid. how about 'X'?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function returning String
    By Slyvester Ping in forum C Programming
    Replies: 6
    Last Post: 04-11-2012, 07:04 AM
  2. Replies: 5
    Last Post: 09-06-2011, 02:59 PM
  3. Returning a string from a function
    By tompagenet in forum C++ Programming
    Replies: 10
    Last Post: 11-12-2003, 06:39 PM
  4. returning a string from a function
    By revelation437 in forum C Programming
    Replies: 6
    Last Post: 12-14-2002, 04:21 AM
  5. returning a string from a function
    By itld in forum Linux Programming
    Replies: 5
    Last Post: 12-03-2001, 01:35 AM