You are on page 1of 2

Computer Programming – I (MCT-143)

Lab Session 10

Concept of do-while LOOP and switch statement

Task 1:
Repeat the Task 3 of previous Lab Session using do-while loop.

Sample output is:


Enter a number: 4
4!=24

You want to calculate again (press Y): y


Enter a number:3
3!=6

You want to calculate again (press Y): n

Task 2:
Write a program that accepts dates written in numerical form and then output them as a complete form.
You can assume that user will enter valid date as well. No need to check for date validity but definitely if
user enters wrong month, error message should be displayed. Use switch statement to display month
name.
(This task was given in Quiz 3 of Session 2011)

Sample output is:


Enter date: 22
Enter Month: 4
Enter Year: 1988
Date is: April 22, 1988

Task 3:
Write a program that performs a survey tally on beverages. The program should prompt for the next
person until a value–1 is entered to terminate the program. Each person participating in the survey should
choose their favorite beverage from the following list:
1. Coffee 2. Tea 3.Coke 4. Orange Juice

Use do-while instruction along with switch statement.


Sample output is:

***************************************************************************************
1. Coffee 2. Tea 3.Coke 4. Orange Juice
***************************************************************************************

Please input the favorite beverage of person #1: Choose 1, 2, 3, or 4


from theabove menu or -1 to exit the program
4
Please input the favorite beverage of person #2: Choose 1, 2, 3, or 4
from theabove menu or -1 to exit the program
1
Please input the favorite beverage of person #3: Choose 1, 2, 3, or 4
from theabove menu or -1 to exit the program
3
Please input the favorite beverage of person #4: Choose 1, 2, 3, or 4
from theabove menu or -1 to exit the program
1
Please input the favorite beverage of person #5: Choose 1, 2, 3, or 4
from theabove menu or -1 to exit the program
1
Please input the favorite beverage of person #6: Choose 1, 2, 3, or 4
from theabove menu or -1 to exit the program
-1

The total number of people surveyed is 5. The results are as follows:


Beverage Number of Votes
********************************
Coffee 3
Tea 0
Coke 1
Orange Juice 1

You might also like