Click here to Skip to main content
11,718,013 members (81,020 online)
Rate this: bad
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
Edited 7-Sep-12 21:11pm
enhzflep at 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 at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 849
1 OriginalGriff 215
2 F-ES Sitecore 210
3 Maciej Los 140
4 Jochen Arndt 120
0 Sergey Alexandrovich Kryukov 1,494
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 8 Sep 2012
Copyright © CodeProject, 1999-2015
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