Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Assignment No. 02
Semester: Fall 2014

CS201: Introduction to Programming

Total Marks: 20

Due Date: 12-12-2014

Lectures covered: 6 to 12


Please read the following instructions carefully before submitting assignment.

It should be clear that your assignment will not get any credit if:


  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)
  • Assignment is in any other format than .CPP




The objective of this assignment is to learn, practice and understand practical usage of

  • Loops
  • Functions



  • 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.



Secret Number Range

No. of attempts










Table 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 messages.


You are required to submit your solution file in .CPP file only.



Views: 10984

Replies to This Discussion

Lets start Discussion

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

how to make choice in this code...!!!!

where iz video file “Sample_Output.mp4”?

 Đ€VÏĻ Ŗ€Đ €Ÿ€ 

For thiz u can use any loop. 

CS 201 Assignment # 1


#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;


// declare and initialize variables
int low = 0, high = 0, secretNumber = 0, userNumber = 0;

cout"My Student ID is BC123456789"endl;

// get input value for lower range
cout"Enter lower range: ";

// get input value for upper range
cout"Enter upper range: ";

// validation check: lower range must be greater than zero
if(low < 1){
cout"The value of lower range must be greater than zero(0)"endl;
system("pause"); // pause output screen
exit(0); // exit the program

// validation check: high range must be greater than low range
else if( high <= low){
cout"The value of high range must be greater than low range"endl;
system("pause"); // pause output screen
exit(0); // exit the program

cout"Computer is calculating a random secret number in the given range...";

// setting random seed value with current system time

// generating secret number
secretNumber = low + (rand() % (high - low + 1 ) );

cout"Please guesss the secret number in the range ["low" - "high"]: ";

if(userNumber > secretNumber){
cout"Oooppssss...your entered number is too high...Computer won"endl;
else if(userNumber < secretNumber){
cout"Oooppssss...your entered number is too low...Computer won"endl;
else if(userNumber == secretNumber) {
cout"Wawoooo...Congratulations!...You won"endl;
cout"Invalid Input"endl;
cout"\n\nSecret Number was: "secretNumberendlendl;



great job 

ye program run q nai hotaa koe bataya ga ???


Don't use this code, it's for Assignment #1 not Assignment # 2

ye run q nai hota prograamm ????


Looking For Something? Search Below

Latest Activity

VIP Member Badge & Others

How to Get This Badge at Your Profile DP


Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service