0
#include <stdio.h>
#define SPACE ' '
void branching_if_judgement(int a, int b){
    if (a > b){
        printf("a(%d) is larger than b(%d)\n", a, b);
    }else {[![enter image description here][1]][1]
        printf("a(%d) is smaller or equal to b(%d)\n", a, b);
    }
}

char branching_if_judgement_char(int a, int b){
    char res;
    if (a > b){
        printf("a(%d) is larger than b(%d)\n", a, b);
        res = 'Y';
    }else {
        printf("a(%d) is smaller or equal to b(%d)\n", a, b);
        res = 'N';
    }
    return res;
}
int main() {
    branching_if_judgement_char(2,3);
}

I follow the example to run the code. And, there are missing the main function in the slide. I add it


So, my question is how to combine all function in the one output, just like the slide.

how to run the output like the example in the slide?

:Slide example

Chun Ki Wu
  • 11
  • 4
  • Hi, I'm not sure, but I think they have ignored the `main` function to show you the essence of the code. The `branching_if_judgement_char` returns a char, so it seems like you need a variable e.g `result` where you save the value from the function: `result = branching_if_judgement_char(2,3);`. Not sure if I got it right. Thanks. – user1098490 Oct 08 '20 at 12:06
  • Maybe this help: https://stackoverflow.com/questions/19828670/xcode-doesnt-write-anything-to-output-console – user1098490 Oct 08 '20 at 12:10
  • @user1098490 the link is not helpful since I have selected All Output – Chun Ki Wu Oct 08 '20 at 12:50
  • Which line should be saved? @user1098490 – Chun Ki Wu Oct 08 '20 at 12:53
  • I don't seem to understand your question: *how to combine all function in the one output* @Chun Ki Wu, I am sorry. – user1098490 Oct 08 '20 at 13:14
  • It's fine, my English is not well. My question is how to run the output like the slide example. @user1098490 – Chun Ki Wu Oct 08 '20 at 13:17
  • if you add in main: `result = branching_if_judgement_char(2,3); printf(result);`. Or maybe it's possible to print directly: `printf(branching_if_judgement_char(2,3));` Thanks for your answer. – user1098490 Oct 08 '20 at 13:59

1 Answers1

0

The function signature tells us that

char branching_if_judgement_char(int a, int b)

it returns a thing of type char, and it takes two things of type int.

So when you call it, you're passing the two things to it, but not taking the thing it's returning.

branching_if_judgement_char(2,3);

Correct code should be

char p = branching_if_judgement_char(2,3);
printf("%c\n", p);

Please find some time to read

puio
  • 1,208
  • 6
  • 19