12-06-2014, 08:23 PM
CS201-Introduction to Programming Assignment No.2, Solutions and Discussions, Fall 2014 Due Date: 12-Dec-2014
Objective:
The objective of this assignment is to learn, practice and understand practical usage of
Loops
Functions
Guidelines:
Code should properly be indented and well commented.
Use only Dev-C++ for this assignment. If you are using any other tool then mention it at top of your code file as comments.
You are recommended to submit only single CPP file. Don’t zip it or paste code in MS word file.
Assignment Description
This assignment is based on our previous assignment and you can use solution of Assignment#1 as a startup code. In Assignment#1, user was asked only once to guess the random number generated by computer. Here, you are required to enhance its capability by introducing three levels (Beginner, Intermediate, and Advance). The range and number of tries/attempts in each level is given below.
Level Secret Number Range No. of attempts
Beginner 1-20 3
Intermediate 1-50 4
Advance 1-100 5
able 1: Secret number range and no. of attempts for different Levels.
It means that if the user selects (say for example) Intermediate level, then program shall generate a random number in ranges 1-50 and asked user to guess that number in 4 attempts. After every wrong attempt, computer will tell the user that your guess was either below or above as before which will help user to make intelligent guess in next attempt.
Sample working of the desired program is shown in attached video file “Sample_Output.mp4”.
Solution Guidelines
You can complete this assignment by using three functions and brief description of each function is given below:
1. selectLevel: This function will essential take input from user to choose desired level. It will also check if the user provides valid input i.e. in range 1 and 3, otherwise appropriate message shall be displayed like shown in the screenshot below.
2. generateSecretNumber: This function will generate a secret random number as per user selected level in the range given in Table 1.
3. guessSecretNumber: This function will allow user to make multiple attempts as per user selected level to guess the secret number along with appropriate message
