Phonetics 5100 Home Security System User Manual


 
113
Chapter 8: C Programming
3. This program simply does not do what it should:
int x;
main()
{
x=input(5);
if (x=10)
{
output(9,1);
}
else
{
output(9,0);
}
}
The problem is that the statement: if (x=10) actually assigns the value of 10 to x. The key is
that it uses a single equals sign ‘=’. To test a condition, use the double equals sign, ‘==’. See
below:
int x;
main()
{
x=input(5);
if (x==10) /* Notice the == */
{
output(9,1);
}
else
{
output(9,0);
}
}