0% found this document useful (0 votes)
7 views2 pages

Lab 0487979798

The document outlines a lab assignment focused on implementing loops in C++ through hands-on exercises. It includes two tasks: creating a number guessing game using a while loop and generating a multiplication table for numbers 2 to 20 using nested loops. Students are instructed to rely on class notes and avoid AI tools or online resources.

Uploaded by

xavier16dude
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Lab 0487979798

The document outlines a lab assignment focused on implementing loops in C++ through hands-on exercises. It includes two tasks: creating a number guessing game using a while loop and generating a multiplication table for numbers 2 to 20 using nested loops. Students are instructed to rely on class notes and avoid AI tools or online resources.

Uploaded by

xavier16dude
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab-4 (Jan 31, 2025)

Objective:

To understands and implement different types of loops in C++ (for, while, and do-while loops)
through hands-on coding exercises.

Instructions:

• No use of any AI-generative tools or online resources. You can use class notes/lectures

Task-1: Number Guessing Game

Write a C++ program where the user tries to guess a randomly generated number between 1 and
100 using a while loop. The program should give hints like "Too High" or "Too Low" until the user
guesses correctly.

Subtasks:
• Take a random number using std::rand() and store it into an integer variable (let’s say
comp_num). update the number as comp_num = comp_num %100 +1 .
• Repeatedly do this in a loop
o Take an integer as input from a user (store into variable guess) and compare it with the
comp_num.
o If the guess number is greater than the comp_num, output “Too High".
o If the guess number is less than the comp_num, output "Too Low",
o If the guess number is equal to the comp_num, output “the guess is correct”. This
resulted into exit from the loop

Example Output:

Guess the number (between 1 and 100): 50


Too high! Try again: 25
Too low! Try again: 37
Correct! The number was 37.

Task-2: Write a C++ program that prints the multiplication table up to 10 for all numbers from 2-20
(using nested loops).
Example Output:

2x1=2
2x2=4
.
.
2 x 10 = 20

3x 1 = 3
3x2=6
.
.
3 x 10 = 30
..


..

5x1=5
5 x 2 = 10
.
.
5 x 10 = 50


20x 1=20
20x2 =40
.
.
20 x10 =200

You might also like