Some quick help please with functions.
Hey this is some of my homework and i only have 3 questions. Here are the questions and what i have tried for my answer. I also put the error that i recieve.
1. Given the char * variables name1, name2, and name3, write a fragment of code that assigns the largest value to the variable max (assume all three have already been declared and have been assigned values).
i put:
Code:
if(strcmp(name1,name2,name3)=name1)
max = name1;
else if(strcmp(name1,name2,name3)=name2)
max = name2;
else ( max = name3;)
errors: You might want to recall what strcmp returns when
one string is greater than another.
You have to use a relational operator in this exercise.
2. Write an expression that evaluates to true if the value of the string variable s1 is greater than the value of string variable s2.
i put:
Code:
strcmp(*s1,*s2) = s1
errors:You might want to recall what strcmp returns when
one string is greater than another.
You have to use a relational operator in this exercise.
There is no need to use an assignment operator here.
3.Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value.
The function can be used as follows:
Code:
int a=31, b=5, c=19 big, small;
minMax(a,b,c,&big,&small);
/* big is now 31 */
/* small is now 5 */
my code:
Code:
void minMax(int a,int b, int c, int &big, int &small){(if(a>b && a>c){
a=big};
if(b>a && b>c){
b=big};
else if(c>a && c>b){
c=big};
else if(a<b && a<c){
a=small};
else if(b<a && b<c){
b=small};
else (c=small);
}
errors:Mismatched ( and }
Common Errors:
- Make sure your if/else statements are correct.
- Make sure you have semicolons at the end of each statement.
- Make sure you are assigning the correct values to big and small.
thanks so much guys