IF Practice Programs

 

These are short practice program that help practice using the IF/ESLEIF/ELSE structure. 

 

Create a folder called IF PROGRAMS within your QBASIC folder.  Save each of these programs in your IF folder with the appropriate name.

 

IF1

 

Write a program that asks the user to enter their grade in high school.  Use data validation to ensure that their grade is 9, 10, 11, or 12.  After they’ve entered their grade, the program should tell them whether they are a freshman, sophomore, junior, or senior.

 

When complete, save in your IF folder as IF1

 

IF2

 

Ernesto’s Eggs has different wholesale prices for their eggs, based on the number sold: 

Quantity

Price

0 – 4 dozen (exclusive)

$0.50 per dozen

4 dozen (inclusive) to 6 dozen (exclusive)

$0.45 per dozen

6 dozen (inclusive) to 11 dozen (exclusive)

$0.40 per dozen

11 dozen or more

$0.35 per dozen

Extra eggs (odd lots) are priced at 1/12th of the per/dozen price

 

Write a program that asks the user for the number of eggs, and then calculates the bill

 

IF3

 

See the program above (IF2).  Assume that instead of keying in the number of eggs, you’d like to print a chart of the price for any quantity up to 120 eggs.  Use loops and if to write a program that displays:

 

# Eggs             Price

1                                              0.04

2                                            0.08

3                                            0.12…etc

 

IF4

 

Write a program that simulates a police radar gun.  The user enters the speed of the car.  If the speed is over 55mph, the program displays “SPEEDING”.  Otherwise, the program displays “SAFE”.

 

IF5

 

Write a program that asks the user to enter an integer and tells whether the integer is EVEN or ODD.  (Hint – How do you know if a number is EVEN?  How could your computer know?)

 

IF6

 

Write a program that ask the user their GPA.  If their GPA is 3.7 or more, the program says “A Honor Roll”.  If their GPA is not 3.7, but is 3.3 or more, the program says “B Honor Roll”.  Otherwise, the program says, “Try Harder!”.

 

IF7

 

Write a program that will convert the user’s weight on Earth to their weight on another planet.  The user should enter their weight and the name of the planet they wish to convert to.  Use the following scale to convert weights:

 

Planet

Multiply Weight By:

Earth

1

Mercury

0.37

Venus

0.88

Mars

0.38

Jupiter

2.64

Saturn

1.15

Uranus

1.15

Neptune

1.12

Pluto

0.04

 

IF8

 

Write a program that generates a random number between 1 and 100.  The user is asked to guess that number and must guess until they get it right.  The program helps them out by giving messages like “guess higher” or “guess lower” after each guess. 

 

IF9

 

Write a program that simulates rock, paper, scissors.  The user enters their pick and the computer generates a random pick.  The program tells what you picked, what the cpu picks, and who the winner is (or tie).