Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function output is only showing as a value of 16

When I run this and input 2 values, it always only ever outputs the value of 16. I never receive anything else. Please can someone show me where I’ve gone wrong with this.

#include <stdio.h>
#include <stdlib.h>

#define result

int higher(int num1 , int num2);

int main (int argc, char *argv[]) {
    int val1;
    int val2;
    int num;

    num = higher(val1, val2);

    printf("Enter two numbers: ");
    scanf("%d %d", &val1, &val2);
    printf("The higher number is: %d\n", num);
    return EXIT_SUCCESS;
}

int higher(int num1 , int num2) {
    // Based on what values are called from the function
    // num1 or num2 should reflect as the highest.
    int result;

    if (num1 <= num2)
        result = num2;
    else
        result = num1;

    return result;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are calling the function before getting the values in scanf it should be like this.

printf("Enter two numbers: ");
scanf("%d %d", &val1, &val2);
num = higher(val1, val2);
printf("The higher number is: %d\n", num);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading