SlideShare a Scribd company logo
1 of 10
C++ Programming
Conditions and loops
Mohammed Jehan
Lecturer
The While Statement
A loop repeatedly executes a set of statements until a particular condition is satisfied.
A while loop statement repeatedly executes a target statement as long as a given
condition remains true.
while (condition) {
statement(s);
}
The loop iterates while the condition is true. At the point when the condition becomes
false, program control is shifted to the line that immediately follows the loop.
The while loop
The loop's body is the block of statements within curly braces.
For example:
int num = 1;
while (num < 6)
{
cout << "Number: " << num << endl;
num = num + 1;
}
The while loop
#include <iostream>
using namespace std;
int main()
{
int num = 1;
while (num < 6)
{
cout << "Number: " << num << endl;
num = num + 1; }
return 0;
}
Using Increment or Decrement in while loop
The increment or decrement operators can be used to change values in the loop.
For example: int num = 1;
while (num < 6) {
cout << "Number: " << num << endl;
num++;
}
num++ is equivalent to num = num + 1.
Obtaining multiple values from the User
A loop can be used to obtain multiple inputs from the user.
Let's create a program that allows the user to enter a number 5 times, each time storing the input
in a variable.
int num = 1;
int number;
while (num <= 5) {
cin >> number;
num++;
}
The above code asks for user input 5 times, and each time saves the input in the number variable.
Multiple values in While Loop
Now let's modify our code to calculate the sum of the numbers the user has entered.
int num = 1;
int number;
int total = 0;
while (num <= 5) {
cin >> number;
total += number;
num++;
}
cout << total << endl;
Multiple values in While Loop
Now let's modify our code to calculate the sum of the numbers the user has entered.
int num = 1;
int number;
int total = 0;
while (num <= 5) {
cin >> number;
total += number;
num++;
}
cout << total << endl;
The code above adds the number entered by the user to the total variable with each loop
iteration. Once the loop stops executing, the value of total is printed. This value is the sum of all
of the numbers the user entered. Note that the variable total has an initial value of 0
Multiple values in While Loop
Now let's modify our code to calculate the sum of the numbers the user has entered.
int num = 1;
int number;
int total = 0;
while (num <= 5) {
cin >> number;
total += number;
num++;
}
cout << total << endl;
The code above adds the number entered by the user to the total variable with each loop
iteration. Once the loop stops executing, the value of total is printed. This value is the sum of all
of the numbers the user entered. Note that the variable total has an initial value of 0
THANK YOU

More Related Content

What's hot

c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2sajidpk92
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 
Assignement of programming & problem solving(3)a.z
Assignement of programming & problem solving(3)a.zAssignement of programming & problem solving(3)a.z
Assignement of programming & problem solving(3)a.zSyed Umair
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structureRumman Ansari
 
Implement ERC20 on TestRPC
Implement ERC20 on TestRPCImplement ERC20 on TestRPC
Implement ERC20 on TestRPCKC Tam
 
Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...hwbloom42
 
Assignment#1
Assignment#1Assignment#1
Assignment#1NA000000
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 
Removal Of Recursion
Removal Of RecursionRemoval Of Recursion
Removal Of RecursionRicha Sharma
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends? ?
 

What's hot (20)

Basic constructs ii
Basic constructs  iiBasic constructs  ii
Basic constructs ii
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Assignement of programming & problem solving(3)a.z
Assignement of programming & problem solving(3)a.zAssignement of programming & problem solving(3)a.z
Assignement of programming & problem solving(3)a.z
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
C++loop statements
C++loop statementsC++loop statements
C++loop statements
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
Implement ERC20 on TestRPC
Implement ERC20 on TestRPCImplement ERC20 on TestRPC
Implement ERC20 on TestRPC
 
Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...Write a C function that returns the length of a string. Function name: strinq...
Write a C function that returns the length of a string. Function name: strinq...
 
Assignment#1
Assignment#1Assignment#1
Assignment#1
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
Removal Of Recursion
Removal Of RecursionRemoval Of Recursion
Removal Of Recursion
 
Inc decsourcefile
Inc decsourcefileInc decsourcefile
Inc decsourcefile
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
 
applet.docx
applet.docxapplet.docx
applet.docx
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends
 

Similar to Lecture 3

C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptxNaumanRasheed11
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6Vince Vo
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8REHAN IJAZ
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptxAqeelAbbas94
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitionsaltwirqi
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05IIUM
 

Similar to Lecture 3 (20)

C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
C++ loop
C++ loop C++ loop
C++ loop
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Control structures
Control structuresControl structures
Control structures
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05
 

More from Mohammed Khan

Module 11 therapeutic intervention play yoga
Module 11 therapeutic  intervention  play yogaModule 11 therapeutic  intervention  play yoga
Module 11 therapeutic intervention play yogaMohammed Khan
 
Module 10 principles of learning, practice, reinforcement understanding spec...
Module 10 principles of learning, practice, reinforcement understanding  spec...Module 10 principles of learning, practice, reinforcement understanding  spec...
Module 10 principles of learning, practice, reinforcement understanding spec...Mohammed Khan
 
Module 3 special education
Module 3 special educationModule 3 special education
Module 3 special educationMohammed Khan
 

More from Mohammed Khan (17)

Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Module 11 therapeutic intervention play yoga
Module 11 therapeutic  intervention  play yogaModule 11 therapeutic  intervention  play yoga
Module 11 therapeutic intervention play yoga
 
Module 10 principles of learning, practice, reinforcement understanding spec...
Module 10 principles of learning, practice, reinforcement understanding  spec...Module 10 principles of learning, practice, reinforcement understanding  spec...
Module 10 principles of learning, practice, reinforcement understanding spec...
 
Module 9 speci ed
Module 9 speci edModule 9 speci ed
Module 9 speci ed
 
Module 8 spec ed
Module 8 spec edModule 8 spec ed
Module 8 spec ed
 
Module 7 special ed
Module 7  special edModule 7  special ed
Module 7 special ed
 
Module 6 spec ed
Module 6 spec edModule 6 spec ed
Module 6 spec ed
 
Module 5 special ed
Module 5 special edModule 5 special ed
Module 5 special ed
 
Module 4 spec needs
Module 4 spec needsModule 4 spec needs
Module 4 spec needs
 
Module 3 special education
Module 3 special educationModule 3 special education
Module 3 special education
 
Module 2 special ed
Module 2 special edModule 2 special ed
Module 2 special ed
 
Module 1 special ed
Module 1 special edModule 1 special ed
Module 1 special ed
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Lecture 3

  • 1. C++ Programming Conditions and loops Mohammed Jehan Lecturer
  • 2. The While Statement A loop repeatedly executes a set of statements until a particular condition is satisfied. A while loop statement repeatedly executes a target statement as long as a given condition remains true. while (condition) { statement(s); } The loop iterates while the condition is true. At the point when the condition becomes false, program control is shifted to the line that immediately follows the loop.
  • 3. The while loop The loop's body is the block of statements within curly braces. For example: int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 1; }
  • 4. The while loop #include <iostream> using namespace std; int main() { int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 1; } return 0; }
  • 5. Using Increment or Decrement in while loop The increment or decrement operators can be used to change values in the loop. For example: int num = 1; while (num < 6) { cout << "Number: " << num << endl; num++; } num++ is equivalent to num = num + 1.
  • 6. Obtaining multiple values from the User A loop can be used to obtain multiple inputs from the user. Let's create a program that allows the user to enter a number 5 times, each time storing the input in a variable. int num = 1; int number; while (num <= 5) { cin >> number; num++; } The above code asks for user input 5 times, and each time saves the input in the number variable.
  • 7. Multiple values in While Loop Now let's modify our code to calculate the sum of the numbers the user has entered. int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl;
  • 8. Multiple values in While Loop Now let's modify our code to calculate the sum of the numbers the user has entered. int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; The code above adds the number entered by the user to the total variable with each loop iteration. Once the loop stops executing, the value of total is printed. This value is the sum of all of the numbers the user entered. Note that the variable total has an initial value of 0
  • 9. Multiple values in While Loop Now let's modify our code to calculate the sum of the numbers the user has entered. int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; The code above adds the number entered by the user to the total variable with each loop iteration. Once the loop stops executing, the value of total is printed. This value is the sum of all of the numbers the user entered. Note that the variable total has an initial value of 0