You are on page 1of 2

Lab# 04

Debugging, Flowcharts & Decision Control Structure


4.1 Objective
The student should practice the following statements:
1. Debugging a code
2. if statements
3. if-else statements
4. flowcharts
4.2 Useful concept
If Statement:
In C++, an "if" statement allows you to conditionally execute code based on whether a
specified condition evaluates to true or false. If the condition is true, the code inside the "if"
statement is executed; otherwise, it is not executed.
Debugging:
Debugging is the process of identifying and correcting errors or bugs in a computer
program. When a program does not behave as expected or produces unexpected results, it is
necessary to debug it to find and fix the issues. Use the given link to debug a code.
https://pythontutor.com/render.html#mode=edit

 Click on Visualize Execution


 Click on Next

4.3 Examples
#include <iostream>
using namespace std;
int main()
{
float marks, total, percent = 0;
cout << "Enter the marks obtained in Project Fundaments: ";
cin >> marks;
cout << "Enter the total marks of the subject: ";
cin >> total;
percent = (marks * 100) / total;
if (percent >= 50)
{
cout << "Congratulations on successfully passing this subject. \n";
}
else
{
cout<<" Sorry you did not pass this course, Better luck next time. \n";
}
return 0;
}

4.4 Exercise for Lab


Draw Flowchart for each task.
Task 1: Write a program that read a number and if it is positive or negative?
Task 2: Write a C++ program that prompts the user to input two numbers and then displays the larger
number among them.

You might also like