Thread: Single function, Two test cases required

  1. #1
    Registered User
    Join Date
    Aug 2018
    Posts
    1

    Single function, Two test cases required

    I am a beginner in programming who has just started his classes.
    In one of the assignments, we had to write a function to return the average of 3 intergers. Which is not a problem, except that there are two test cases and both have to be passed at once. (1,2,3 average 2. 10,20,30 average 20). I'm not looking for any direct answer but would like to confirm, one function should be able to return only 1 variable if i'm not mistaken? I have tried submitting two functions returning both variables only to have my second function rejected. Ultimately still unable to pass both test case at once.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So what code do you have?

    How does this fail for example.
    Code:
    printf("%d\n",average(1,2,3));
    printf("%d\n",average(10,20,30));
    > one function should be able to return only 1 variable if i'm not mistaken?
    Yes, that is the case.
    To solve this, you can either
    • return a structure
    • pass pointers to variables where you want multiple answers stored.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Test cases from C program
    By Satya in forum C Programming
    Replies: 1
    Last Post: 10-21-2017, 11:46 PM
  2. generate test cases
    By lisa18 in forum C++ Programming
    Replies: 3
    Last Post: 08-22-2006, 07:16 PM
  3. Test cases
    By desertstorm in forum C Programming
    Replies: 2
    Last Post: 05-13-2006, 12:06 AM
  4. test cases
    By krithi in forum C Programming
    Replies: 10
    Last Post: 12-12-2002, 07:13 AM
  5. Deriving Test Cases
    By test in forum C Programming
    Replies: 2
    Last Post: 10-01-2002, 05:45 PM

Tags for this Thread