Solution for Exercise 8-15
ex0815
#include <stdio.h> int main() { int coordinate; printf("Input target coordinate: "); scanf("%d",&coordinate); if( coordinate < -5 || coordinate > 5 ) { puts("Close enough!"); } else { puts("Target is out of range!"); } return(0); }
Notes
* The easiest way to construct the comparison in Line 9 is to read the directions from the book: "...make the condition true when the value of variable coordinate is less than -5 or greater than 5." Now look at Line 9:
That statement reads, "If the value of variable coordinate
is less than -5 or the value of variable coordinate
is greater than 5." Or, to be brief about it, "If coordinate
is less than -5 or coordinate
is greater than 5." Or:
* As long as you read the <
, ||
, and >
symbols properly, you can get the comparison correct.
Copyright © 1997-2024 by QPBC.
All rights reserved