100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary C++ if. if...else and Nested if...else $5.49   Add to cart

Summary

Summary C++ if. if...else and Nested if...else

 6 views  0 purchase

The document provides detailed notes on conditional statements in C++, focusing on if, if...else, and nested if...else constructs. It explains their syntax and usage for decision-making in programs. Practical examples illustrate how these statements control program flow based on conditions. The not...

[Show more]

Preview 2 out of 12  pages

  • July 25, 2024
  • 12
  • 2023/2024
  • Summary
All documents for this subject (10)
avatar-seller
peterkuria3
ELITE TUTORING




C++ if, if...else and Nested if...else
In this topic, we will learn about the if...else statement to create decision
making programs with the help of examples.

In computer programming, we use the if...else statement to run one block of
code under certain conditions and another block of code under different
conditions.
For example, assigning grades (A, B, C) based on marks obtained by a
student.

• if the percentage is above 90, assign grade A
• if the percentage is above 75, assign grade B
• if the percentage is above 65, assign grade C




There are three forms of if...else statements in C++.
1. if statement
2. if...else statement
3. if...else if...else statement




C++ if Statement
The syntax of the if statement is:

if (condition) {
// body of if statement

, ELITE TUTORING



}


The if statement evaluates the condition inside the parentheses ( ).

• If the condition evaluates to true , the code inside the body of if is
executed.
• If the condition evaluates to false , the code inside the body of if is
skipped.

Note: The code inside { } is the body of the if statement.




How if Statement Works




Example 1: C++ if Statement
// Program to print positive number entered by the user
// If the user enters a negative number, it is skipped

#include <iostream>
using namespace std;

int main() {

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller peterkuria3. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

82956 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.49
  • (0)
  Add to cart