If error

Noob programmer here, so be patient please. :)

So, I tried everything for this program to work, the code can explain by himself but if in case that it can't be understandable I'll explain.
The user enters two numbers and the program see if there's one positive, if there are two positives/negatives or if the both numbers are zero.

Code's here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

int main()
{
    int st, nd;

    printf("Enter the first number\n");
    scanf("%d", &st);
    printf("Enter the second number\n");
    scanf("%d", &nd);

    if (st = 0 && nd = 0) printf("Both are zeros"); return 0;
    if (st = 0 || nd = 0) printf("Zero is not a positive or a negative"); return 0;

    {
    if (st < 0 || nd > 0) printf("One of the numbers are positive");
    if (st > 0 || nd < 0) printf("One of the numbers are positive");
    if (st > 0 && nd > 0) printf("Both are positive");
    if (st < 0 && nd < 0) printf("Both are negative");
    }

    return 1;
}


Code::Blocks error:

lvalue required as left operand of assignment

In line 12 and 13.

What I'm doing wrong, thanks in advance!
You are using = instead of == on line 12 and 13.

If you want more than one statement to be part of the if statement you have to put them inside curly brackets . As you have it now the return statements is not part of the if statements and will always be executed.

1
2
if (st == 0 && nd == 0) { printf("Both are zeros"); return 0; }
if (st == 0 || nd == 0) { printf("Zero is not a positive or a negative"); return 0; }

Last edited on
Thanks, it worked, but now the program doesn't return any message.
Topic archived. No new replies allowed.