INTERACTIVE TEST 4: If then else, Relational operators, Constants | Notes | Tests | Home Page |
This browser does not support JavaScript. In order to use this test, please update your browser to a JavaScript compatible browser, or choose the CGI version of this test. Internet Explorer browsers are updated by http://www.microsoft.com/ie/, and Netscape browsers updated by accessing http://www.netscape.com/
1. Which of the following is an invalid Pascal relational operator
== <> < >
2. Write a Pascal statement which compares the integer variable sum to the constant value 10, and if it is the same prints the string "Good guess"
if sum = 10 then writeln("Good guess"); if (sum == 10) then writeln('Good guess'); if (sum == 10) writeln('Good guess'); if sum = 10 then writeln('Good guess');
3. Write a Pascal statement which compares the character variable letter to the character variable chinput, and if it is not the same, prints the value of letter
if letter <> chinput then writeln( 'letter' ); if letter < chinput writeln( "letter" ); if letter <> chinput then writeln( letter ); if letter > chinput then writeln( letter );
4. Write a Pascal statement to compare the character variable letter to the character constant 'A', and if less, prints the text string "Too low", otherwise print the text string "Too high"
if letter > 'Z' then writeln('Too low') else writeln('Too high'); if letter < 'A' then writeln('Too low'); else writeln('Too high'); if letter <> 'A' then writeln('Too low') else writeln('Too high'); if letter < 'A' then writeln('Too low') else writeln('Too high');
5. Write a Pascal statement to display the text string "Valve open", if the variable waterflow is equal to 1, AND the variable outputvalue is equal to 0
if (waterflow = 1) AND (outputvalue = 0) then writeln('Valve open'); if (waterflow = 1) OR (outputvalue = 0) then writeln('Valve open'); if (waterflow = 0) AND (outputvalue = 1) then writeln('Valve open'); if (waterflow = 1) AND (outputvalue = 0) then writeln('Valve closed');
6. Write a Pascal statement which declares a constant called MAXSIZE with a value of 80
constant MAXSIZE = 80; const MAXSIZE = 80; const MAXSIZE 80; constant MAXSIZE = 80
7. Write a Pascal statement which will display the value of the real variable degrees using a fieldwidth of 5 with three decimal places
writeln("Degrees = ", degrees:3:5 ); writeln('Degrees = ', degrees:3:5 ); writeln('Degrees = , degrees:5:3' ); writeln('Degrees = ', degrees:5:3 );
Copyright B Brown/P Henry, 1988-1999. All rights reserved.