hello

hey guys need some help on a question.

show the prototype (i.e. declaration) of a function that passes an int by value, a float by value, and a char by value and returns a character value.
We can't really help without giving away the answer.

Maybe take a guess at it, and we can point out your mistakes?
int passval(val1,val2)

float passval(val1,val2)

char passval(char, char)
char passval(char, char)


This is very close.

This is returning a char, and has 2 char's passed to the function by value.

So the return type is correct. But the parameters are wrong. You need to pass in an int, a float, and a char.

Also, prototypes have to end with a semicolon ;
ya that's what I'm having trouble with is figuring out what should be in the parameters. and I'm not entirely sure what, pass an int, a float, and a char, actually mean.
1
2
3
4
5
6
7
char passval( char, char )
                ^     ^
                |     |
                |     |
     passing a char   |
                      |
               and a char


So if you're passing 2 chars... what do you think you'd have to change to pass a int and a float?
char passval(char, int);?
or
char passval(char, float);?
char passval(char, int);

This passes a char and an int

char passval(char, float);

This passes a char and a float.


You need to pass an int, a float, and a char. In that order.


EDIT:

The basic syntax of a function is:

 
returntype functionname(paramtype1, paramtype2, paramtype3, etc);


So say you want a function that:
- returns an int
- passes a char and a double by value as parameters
- is named "myfunction"

It would look like this:

int myfunction( char, double );



Here, your assignment doesn't seem to care what the function is named, so that doesn't matter as long as it's a legal name (no spaces or weird symbols). All you have to do is get the return type and parameters right.
Last edited on
I'm sorry, are you saying i need to put three arguments inside one parameter, such as,

int passval(int,float,char);
int passval(int,float,char);

This has the parameters correct. However you changed the return type. The function needs to return a char, not an int.

I'm sorry, are you saying i need to put three arguments inside one parameter, such as,


Your terminology is a little wonky, which might be why this is confusing.

"parameter" and "argument" basically mean the same thing (I think there is a subtle difference, but I can never remember what it is, and the two terms are largely interchangeable).

arguments go inside of the same set parenthesis
ya, sorry. thanks for your time I'm still new at this. i can tell C++ takes many years of doing it to become efficient and flawless with it. well i guess ill just keep plugging away.
Topic archived. No new replies allowed.