Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COP 2220 Intro to programming in C (answer in C, NOT in C++), please include com

ID: 3812766 • Letter: C

Question

COP 2220 Intro to programming in C (answer in C, NOT in C++), please include comments.

1. Write a function definition for a user-defined function called GotIt. The function takes two integer arguments, input and output.

Your function should:

*If input and output are the same:

---------Display “try again” on the monitor

---------Return the input

*If output is greater than the input:

----------Display “high yield” on the monitor

----------Return the output

*If the output is less than input:

----------Display “something lost” on the monitor

----------Return 0

Declare all necessary variables.

Explanation / Answer

#include<stdio.h>
#include<string.h>
int GotIt(int input, int output) {
if(input == output){
printf("try again ");
return input;
}
else if(output > input){
printf("high yield ");
return output;
}
else{
printf("something lost ");
return 0;
}
}

int main() {
printf("%d ", GotIt(3,3));
printf("%d ", GotIt(5,3));
printf("%d ", GotIt(3,5));
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

try again                                                                                                                                                                                                                                                              

3                                                                                                                                                                                                                                                                      

something lost                                                                                                                                                                                                                                                         

0                                                                                                                                                                                                                                                                      

high yield                                                                                                                                                                                                                                                             

5