Lab 1 - Making Decisions
Lab 1 - Making Decisions
1. Math Tutor
Write a program that can be used as a math tutor for a young student. The program should display two
random numbers to be added, such as
247
+129
The program should then pause while the student works on the problem. When the student is ready to
check the answer, he or she can press a key and the program will display the correct solution:
247
+129
376
2. Word Game
Write a program that plays a word game with the user. The program should ask the user to enter the
following:
After the user has entered these items, the program should display the following story, inserting the user’s
input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of AGE, NAME
went to college at COLLEGE. NAME graduated and went to work as a PROFESSION.
Then, NAME adopted a(n) ANIMAL named PETNAME. They both lived happily ever
after!
3. Interest Earned
Assuming there are no deposits other than the original investment, the balance in a savings account after
one year may be calculated as
𝑅𝑎𝑡𝑒 !
𝐴𝑚𝑜𝑢𝑛𝑡 = 𝑃𝑟𝑖𝑛𝑐𝑖𝑝𝑎𝑙 ∗ 91 + =
𝑇
Principal is the balance in the savings account, Rate is the interest rate, and T is the number of times
the interest is compounded during a year (T is 4 if the interest is compounded quarterly).
Write a program that asks for the principal, the interest rate, and the number of times the interest is
compounded. It should display a report similar to
Input Validation: Make sure the number of calories and fat grams are not less than 0. Also, the number of
calories from fat cannot be greater than the total number of calories. If that happens, display an error
message indicating that either the calories or fat grams were incorrectly entered.
𝑎𝑟𝑒𝑎 = 𝜋𝑟 "
Use 3.14159 for 𝜋 and the radius of the circle for r. If the user enters 2, the program should ask for the
length and width of the rectangle and then display the rectangle’s area. Use the following formula: