To study and implement C++ decision making statements
Decision-making statements control the flow of a program based on conditions. Key types include:
Executes one block if the condition is true, another if false.
these are used when you need to check multiple conditions in a hierarchical manner. An if or else block can contain another if-else statement inside it. This is useful for more complex decision-making processes.
it is used for doing mathematical calculations among some given values.
Used in some languages to handle multiple conditions, mimicked in Python using dictionaries.
//subham
//23070123132
//entc b2
#include <iostream>
using namespace std;
int main()
{
double n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
cout << "Largest number: " << n1;
else if(n2 >= n1 && n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
return 0;
}
//subham
//23070123132
//entc B2
//experiment 5
#include <iostream>
using namespace std;
int main()
{
double n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if (n1 >= n2)
{
if (n1 >= n3)
cout << "Largest number: " << n1;
else
cout << "Largest number: " << n3;
}
else {
if (n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
}
return 0;
}
//subham
//23070123132
//entc B2
//experiment 5
#include<iostream>
using namespace std;
int main() {
char oper;
float num1, num2;
cout << "Enter an operator (+, -, *, /): ";
cin >> oper;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
switch (oper) {
case '+':
cout << num1 << " + " << num2 << " = " << num1 + num2 << endl;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1 - num2 << endl;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1 * num2 << endl;
break;
case '/':
if (num2 != 0)
cout << num1 << " / " << num2 << " = " << num1 / num2 << endl;
else
cout << "Error! Division by zero." << endl;
break;
default:
cout << "Error! The operator is not correct" << endl;
break;
}
return 0;
}
//subham
//23070123132
//entc B2
//experiment 5
#include<iostream>
using namespace std;
int main()
{
int choice;
cout << "1. Monday" << endl
<< "2. Tuesday" << endl
<< "3. Wednesday" << endl
<< "4. Thursday" << endl
<< "5. Friday" << endl
<< "6. Saturday" << endl
<< "7. Sunday" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch(choice) {
case 1:
cout << "Monday" << endl;
break;
case 2:
cout << "Tuesday" << endl;
break;
case 3:
cout << "Wednesday" << endl;
break;
case 4:
cout << "Thursday" << endl;
break;
case 5:
cout << "Friday" << endl;
break;
case 6:
cout << "Saturday" << endl;
break;
case 7:
cout << "Sunday" << endl;
break;
default:
cout << "Wrong Input" << endl;
break;
}
return 0;
}
if else: statement for executing a block if it is true otherwise for false.
nested if else: are used when you need to check multiple conditions in a hierarchical manner.
calculator statement:is used for doing mathematical calculations among some given values.
Switch Case Statement: Used in some languages to handle multiple conditions, mimicked in Python using dictionaries.
Decision-making statements in programming control the flow of execution based on conditions. The if-else statement executes different code blocks depending on whether a condition is true or false, while the nested if else statement allows for multiple conditions to be checked in sequence. The switch statement provides a way to select one of many code blocks to execute based on the value of an expression, ideal for handling discrete values. calculator helps in doing mathematical operations.