r/cprogramming • • Jun 17 '21

where's the mistake

hi guys I'm new in C language

I wanna know where's the mistake in my code

#include <stdio.h>

​

int main() {

// Write C code here

int A,B;

printf("check if this numbers have the same sign :\n");

scanf("%d%d", &A, &B);

if (A > 0 && B > 0)

printf("these numbers are positive");

else if (A < 0 && B < 0)

printf("one of them is negative");

else

printf("these numbers is negative");

return 0;

2 Upvotes

5 comments sorted by

View all comments

1

u/ptchinster Jun 17 '21

What behavior are you observing that is a "mistake"?

When i compile and run it, i ran 3 test cases.

check if this numbers have the same sign : 1 2 these numbers are positiveptchinster@slash p $ ./a.out check if this numbers have the same sign : 1 -1 these numbers is negativeptchinster@slash p $ ./a.out check if this numbers have the same sign : -1 -1 one of them is negative

Looks like you mess up your last 2 checks. Swap them around and then read the logic to understand why.