130 likes | 271 Views
TrueBASIC Ch 4 & 5 Sample Problems. What are the errors? (4 total). INPUT age IF age > 7 THEN PRINT "rollercoaster" ELSE PRINT " ferris wheel" IF age < 10 THEN PRINT "Happy Meal" ELSEIF age < 18 PRINT "Ice Cream" ELSE THEN PRINT "Parfait" END IF.
E N D
What are the errors? (4 total) INPUT age IF age > 7 THEN PRINT "rollercoaster" ELSE PRINT "ferris wheel" IF age < 10 THEN PRINT "Happy Meal" ELSEIF age < 18 PRINT "Ice Cream" ELSE THEN PRINT "Parfait" END IF
What are the errors? (4 total) INPUT age IF age > 7 THEN PRINT "rollercoaster" ELSE PRINT "ferris wheel" IF age < 10 THEN PRINT "Happy Meal" ELSEIF age < 18 THEN PRINT "Ice Cream" ELSE THEN PRINT "Parfait" END IF END • Single line IF-ELSE must all be on one line • ELSEIF needs a THEN after condition • ELSE does not need a THEN • Must have an END statement
What is the output? LET x = 10 LET y = 12 IF x > 12 - 10 / 10 THEN PRINT "1" IF x > (12 - 10) / 10 THEN PRINT "2" IF x > (12 - 10 / 10) THEN PRINT "3" IF NOT x > 10 THEN PRINT "4" IF x > y OR y > x THEN PRINT "5" IF NOT x > y OR NOT y > x THEN PRINT "6" END
What is the output? LET x = 10 LET y = 12 IF x > 12 - 10 / 10 THEN PRINT "1" IF x > (12 - 10) / 10 THEN PRINT "2" IF x > (12 - 10 / 10) THEN PRINT "3" IF NOT x > 10 THEN PRINT "4" IF x > y OR y > x THEN PRINT "5" IF NOT x > y OR NOT y > x THEN PRINT "6" END • 2 • 4 • 5 • 6
What is the output? LET x = 14 SELECT CASE x CASE 10 TO 20, 25 TO 35 PRINT "A" CASE 10 TO 20 PRINT "B" CASE ELSE PRINT "C" END SELECT END
What is the output? LET x = 14 SELECT CASE x CASE 10 TO 20, 25 TO 35 PRINT "A" CASE 10 TO 20 PRINT "B" CASE ELSE PRINT "C" END SELECT END A
What are the errors? (4 total) DATA 12 READ x PRINT IF (x < 17 AND IS NOT 13) THEN PRINT "Okay" READ y IF (y > 8) THEN PRINT "Not Okay" ELSE PRINT "Really Bad" DATA 14, 15 READ z, m IF (z < m OR m <> z) PRINT "Error" END
What are the errors? (4 total) DATA 12 READ x PRINT IF (x < 17 AND x <> 13) THEN PRINT "Okay" READ y IF (y > 8) THEN PRINT "Not Okay " ELSE PRINT "Really Bad" DATA 14, 15, 16 READ z, m IF (z < m OR m <> z) THEN PRINT "Error" END • “IS NOT” is not valid syntax in an IF condition • Single line IF-ELSE must all be on one line • Insufficient Data • IF statement must be followed by THEN
Write a One Line TrueBASIC Statement for each of the Following Commands Ask the user for his/her name Print winner when the team is Rutgers, otherwise print loser Calculate dollars spent as quantity times price
Write a One Line TrueBASIC Statement for each of the Following Commands Ask the user for his/her name INPUT PROMPT "What is your name? ": name$ Print winner when the team is Rutgers, otherwise print loser IF(team$ = "Rutgers") THEN PRINT "winner" ELSE PRINT "Loser" Calculate dollars spent as quantity times price LET dollars_spent = quantity * price
Write a One Line TrueBASIC Statement for each of the Following Commands Get data (not from user) for 3 car name variables Provide the values for 3 car names Display to the user the contents of the num variable, but put three tabs in front
Write a One Line TrueBASIC Statement for each of the Following Commands Get data (not from user) for 3 car name variables READ car1$, car2$, car3$ Provide the values for 3 car names DATA "Grand Prix", "Camaro", "Mustang" Display to the user the contents of the num variable, but put three tabs in front PRINT ,,,num