This program simply does not do what it should – Phonetics Sensaphone ISACC 5000 User Manual

Page 113

Advertising
background image

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);

}

}

Advertising
This manual is related to the following products: