CMSC 104, Fall 2012
Lab 4
Objectives:
For this lab you are to write several C programs to solve the following problems. Try programs at your ability level first.
Warm-Up
- Print the numbers 1 to 100, showing only 10 numbers per line.
Beginner
- Create a menu that continually prompts the user to enter 'H' to print a greeting in English,
A to print a greeting in Hawaiin, 'N' to print a greeting in Hindi,
and S to print a greeting in Hebrew.
The menu should also include an option 'E' which exits the program.
Menu should look something like this:
Please enter: H -> To print greeting in English A -> To print greeting in Hawaiian N -> To print greeting in Hindi S -> To print greeting in Hebrew E -> To exit
Intermediate
- Add functionality to the menu that you created in the beginner section such that
when the user enters 'H', it prints "Hello"; 'A' it prints "Aloha"; 'N' it prints "Namasthe";
and S it prints "Shalom". When the user enters 'E', the program should print "Adios"
before it exits the program.
First, write the menu program using if/else statements to handle the choices. Then, redo it using "switch" statements.
Advanced
- You enter your favorite store with $74.87. Your favorite items cost $4.21, $4.52, and $4.63 respectively. You spend all of your money, you buy one of each item and you buy a total of 17 items. How many items of each did you buy?
Think carefully about how you would do this, before you start coding it!