![Introduction to Programming with C++, 3rd edition](https://www.bartleby.com/isbn_cover_images/9780133377477/9780133377477_largeCoverImage.gif)
Concept explainers
(a)
Explanation of Solution
Given: The following code:
if (number % 2 == 0)
cout << number << " is even";
if (number % 5 == 0)
cout << number << " is multiple of 5";
To find: The output of the code.
Solution:
When the value of the number is 14.
The output of the code will be “14 is even�. In this case, both the ‘if’ statements will be evaluated but only the first ‘if’ statement will be executed.
// Header files
#include
// Header files
#include
//Declaring the namespace
using namespace std;
// Declaring the main of code
int main() {
// Declaring the variable.
int number=14;
// Using the if-statement.
if(number % 2 == 0)
// Displays the message.
cout << number << " is even";
// Using the if-statement.
if(number % 5 == 0)
// Displays the message.
cout << number << " is multiple of 5";
// Using return statement
return 0;
}
When the value of the number is 15.
The output of the code will be “15 is multiple of 5�. In this case, both the ‘if’ statements will be evaluated but only the second ‘if’ statement will be executed.
// Header files
#include
// Header files
#include
//Declaring the namespace
using namespace std;
// Declaring the main of code
int main() {
// Declaring the variable...
(b)
Explanation of Solution
Given: The following code:
if (number % 2 == 0)
cout << number << " is even";
else if (number % 5 == 0)
cout << number <<" is multiple of 5";
To find: The output of the code.
Solution:
When the value of the number is 14.
The output of the code will be “14 is even�. In this case, the ‘else-if’ statement will be evaluated only when the condition of the ‘if’ statement is false. Here, the condition of the ‘if’ statement is true. Hence, only the ‘if’ statement will be executed.
// Header files
#include
// Header files
#include
//Declaring the namespace
using namespace std;
// Declaring the main of code
int main() {
// Declaring the variable.
int number=14;
// Using the if-statement.
if(number % 2 == 0)
// Displays the message.
cout << number << " is even";
// Using the else-if-statement.
else if(number % 5 == 0)
// Displays the message.
cout << number << " is multiple of 5";
// Using return statement
return 0;
}
When the value of the number is 15.
The output of the code will be “15 is multiple of 5�. In this case, the ‘else-if’ statement will be evaluated only when the condition of the ‘if’ statement is false. Here, the condition of the ‘if’ statement is false. Hence, only the ‘else-if’ statement will be executed.
// Header files
#include
// Header files
#include
//Declaring the namespace
using namespace std;
// Declaring the main of code
int main() {
// Declaring the variable...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 3 Solutions
Introduction to Programming with C++, 3rd edition
- After our initial deployment for our ML home based security system, the first steps we took to contribute further to the project, we conducted load testing, tested and optimize for low latency, and automated user onboarding. What should be next?arrow_forwardWhy investing in skills and technology is a critical factor in the financial management aspect of system projects.arrow_forwardwhy investing in skills and technology is a critical factor in the financial management aspect of systems projects.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)