Parameter return question

This is a discussion on Parameter return question within the C Programming forums, part of the General Programming Boards category; Here is the question: Write the definition of a function printAttitude , which has an int parameter and returns nothing. ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    11

    Parameter return question

    Here is the question:


    Write the definition of a function printAttitude , which has an int parameter and returns nothing. The function prints a message to standard output depending on the value of its parameter.
    If the parameter equals 1, the function prints disagree
    If the parameter equals 2, the function prints no opinion
    If the parameter equals 3, the function prints agree
    In the case of other values, the function does nothing.


    Each message is printed on a line by itself.

    my code:

    Code:
    void printAttitude(int)
    {
    if int==1 
    printf("disagree\n");
    if int==2
    printf("no opinion\n");
    if int==3
    printf("agree\n");
    }
    im getting a compile error, but i dont know which because this is an online lab kinda thing.
    anyone know what i'm doing wrong or have tips? i tried a few other things but to no avail.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,292
    "int" is just the data type. You need to declare a variable after it in the argument list, and use that variable in your "if()" statements (not the data type "int").
    Also, the argument to an "if()" statement should be enclosed in parenthesis.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    11
    okay i tried:
    Code:
    void printAttitude(int a)
    {
    if (a==1)
    printf("disagree\n");
    if (a==2)
    printf("no opinion\n");
    if (a==3)
    printf("agree\n");
    }
    but still no dice, this is what the lab is telling me:


    CTest1.c: In function 'printAttitude':
    CTest1.c:4: error: stray '\177' in program
    CTest1.c:6: error: stray '\177' in program

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,469
    It looks like somehow you managed to get a stray character or two in your source code. Try deleting the lines and retyping them, then save and recompile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about ^<parameter>
    By mcmillhj in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2011, 02:30 PM
  2. parameter passing question
    By Ace Rockolla in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2010, 10:54 AM
  3. Parameter and return value specifics
    By Zaff in forum C Programming
    Replies: 5
    Last Post: 07-26-2006, 09:36 AM
  4. question in alias parameter`
    By ssharish in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2005, 06:16 AM
  5. more than one return parameter
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 09-06-2001, 03:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21