Click here to Skip to main content
12,892,810 members (60,708 online)
Rate this:
Please Sign up or sign in to vote.
See more: C
Yes! The frist time try "if-else". Like I said above, here is the code:

   int a,b,x;
   printf("\n Input a: ");
   printf("\n Input b: ");
   if (a=0)
      if (b=0)
         printf("\nThe equation has unlimited result");
         printf("\nThe equation has no result");
      printf("\nThe equation has only 1 result x= %d", x);

The problem is: I have compiled successfully in Dev-C++. But when I run it, the program crash after input 2 numbers (a and b) (The program has stoped working...).

[edit]Indentation corrected so the flow is clear - OriginalGriff[/edit]
Posted 7-Sep-12 17:18pm
Updated 7-Sep-12 21:11pm
enhzflep 7-Sep-12 23:46pm

#include <stdio.h>
int main()
int a=2, b=10;
if (a=b)
printf("Oops! Think I stuffed-up my comparison. I should've used == instead of =\n");
printf("how the hell did program execution get here?\n");
Minh Hikari 8-Sep-12 1:10am
yeah! I think i unserstand what you mean...:D Thank you very much!!! But i still have a question: what is the different between "=" and "=="?
enhzflep 8-Sep-12 1:13am
Well, = is an assignment operator, while == is a comparison operator.

a = 5; - assignment (Set a to 5)
if (a==5) - comparison (Check if a is 5)
Minh Hikari 8-Sep-12 1:19am
ok! I understand clearly now..^^ Thank you very much!!!^^

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Make a habit of doing comparisons like this :
if (0 == a)
if you mistakenly do this :
if (0 = a)
compilation will fail because 0 cannot be assigned.
This kind of error is very common and even professional programmers still make this error sometimes, but the above trick helps avoid having to look for this kind of error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 8 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100