- C++ Programming Basics
- C++ Tutorial
- C++ Environment Setup
- C++ Character Set
- C++ Keywords
- C++ Identifiers
- C++ Constants
- C++ Punctuators
- C++ Program Structure
- C++ Basic Syntax
- C++ Comments
- C++ Basic Programs
- C++ Input Output Operator
- C++ Input Output Stream
- C++ Type & Variable
- C++ Data Types
- C++ Data Type Modifiers
- C++ Variables
- C++ Variable Types
- C++ Variable Scope
- C++ Storage Classes
- C++ Formatting Output
- C++ Operators
- C++ Operators
- C++ Type Conversion
- C++ Numbers
- C++ Assignment Operator
- C++ Shorthand
- C++ Flow of Control
- C++ Statements
- C++ Flow Control
- C++ Decision Making
- C++ if if-else if-else-if switch
- C++ Loops
- C++ for while do-while Loop
- C++ break continue goto
- C++ Standard Library
- C++ Standard Library
- C++ Header Files
- C++ Character String
- C++ Mathematical Functions
- C++ Functions
- C++ Functions
- C++ Function Types
- C++ Function Prototype
- C++ Function Call
- C++ Function Return
- C++ Friend Function
- C++ Scope Rules
- C++ Arrays & Strings
- C++ Arrays
- C++ One Dimensional Arrays
- C++ Two Dimensional Arrays
- C++ Strings
- C++ Data Structure
- C++ Data Structure
- C++ Access Structure Member
- C++ Nested Data Structure
- C++ Structure Array
- C++ Pass Structure to Function
- C++ typedef
- C++ #define
- C++ Programming Pointers
- C++ Pointers
- C++ Memory Map
- C++ Free Store
- C++ Declare Initialize Pointers
- C++ Dynamic Memory Allocation
- C++ Pointers & Arrays
- C++ Pointers & Const
- C++ Pointers & Functions
- C++ Pointers & Structures
- C++ Objects as Function Arguments
- C++ Pointers & Objects
- C++ References
- C++ File Handling
- C++ File Handling
- C++ File Streams
- C++ Data Files
- C++ Opening & Closing Files
- C++ Steps to Process Files
- C++ Change Stream Behaviour
- C++ Sequential I/O Operations
- C++ Detecting EOF
- C++ File Pointers Random Access
- C++ Binary Files Operations
- C++ Error Handling
- C++ Object Oriented
- C++ Object Oriented
- C++ Function Overloading
- C++ Classes & Objects
- C++ Constructors & Destructors
- C++ Inheritance
- C++ Encapsulation
- C++ Polymorphism
- C++ Data Abstraction
- C++ Interfaces
- C++ Programming Advance
- C++ Linked Lists
- C++ Stacks
- C++ Queues
- C++ Date Time
- C++ Preprocessors
- C++ Exception Handling
- C++ Namespaces
- C++ Dynamic Memory
- C++ Multithreading
- C++ Templates
- C++ Signal Handling
- C++ Web Programming
- C++ Programming Examples
- C++ Programming Examples
- C++ Programming Test
- C++ Programming Test
- Give Online Test
- All Test List
C++ Decision Making
Decision making statements in C++ allows you to specify one or more condition to be evaluated by your program to run specific statement(s). There are following types of decision making statements available in C++. You will learn all about these C++ decision making statements in detail, in C++ if if-else if-else-if switch Statements tutorial.
You will learn in detail about the above C++ decision making statements in next tutorial.
C++ Decision Making Example
Let's take some example, demonstrating the above listed C++ decision making statements practically. As already told, that the explanation and details description of this chapter is described in the next tutorial.
/* C++ Decision Making */ #include<iostream.h> #include<conio.h> #include<stdlib.h> void main() { clrscr(); int a, b; char choice; cout<<"Enter any two numbers: "; cin>>a>>b; cout<<"\n"; cout<<"1. Add\n"; cout<<"2. Subtract\n"; cout<<"3. Multiply\n"; cout<<"4. Divide\n"; cout<<"5. Nothing\n"; cout<<"\nWhat do you want ? (1-5) "; cin>>choice; cout<<"\n"; switch(choice) { case '1' : cout<<a+b; break; case '2' : cout<<a-b; break; case '3' : cout<<a*b; break; case '4' : cout<<a/b; break; case '5' : exit(1); default : cout<<"Wrong choice..!!..Press any key to exit..\n"; getch(); exit(2); } getch(); }
Here is the sample run of the above C++ decision making program:

Here is another sample run of the same, above C++ decision making program:

Here is another C++ program, also demonstrating C++ decision making practically
/* C++ Decision Making */ #include<iostream.h> #include<conio.h> #include<stdlib.h> void main() { clrscr(); int a, b; char choice; cout<<"Enter any two numbers: "; cin>>a>>b; cout<<"\n"; cout<<"1. Add\n"; cout<<"2. Subtract\n"; cout<<"3. Multiply\n"; cout<<"4. Divide\n"; cout<<"5. Nothing\n"; cout<<"\nWhat do you want ? (1-5) "; cin>>choice; cout<<"\n"; if(choice == '1') { cout<<a+b; } else if(choice == '2') { cout<<a-b; } else if(choice=='3') { cout<<a*b; } else if(choice=='4') { cout<<a/b; } else if(choice=='5') { exit(1); } else { cout<<"Wrong choice..!!..Press any key to exit..\n"; getch(); exit(2); } getch(); }
Here are the two sample runs of the above C++ decision making program:


More Examples
Here are some more C++ decision making programs, that you may like:
- Check Even or Odd
- Check Prime or Not
- Check Alphabet or Not
- Check Vowel or Not
- Check Leap Year or Not
- Check Reverse equal Original
- Add Subtract Multiply Divide
- Make Calculator
- Check Palindrome or Not
- Check Armstrong or Not
« Previous Tutorial Next Tutorial »