Fix some indentation and change some typo (#22017)
This commit is contained in:
committed by
Christopher McCormack
parent
1606de6c51
commit
d93ad2c00b
@ -62,11 +62,11 @@ else
|
||||
//Program to check whether number entered by user is positive or negative
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int no;
|
||||
cout << "Enter a number: " << endl;
|
||||
|
||||
cin >> no;
|
||||
|
||||
// condition to check if number is positive or negative
|
||||
@ -116,19 +116,22 @@ This step is always printed
|
||||
If we have to make decisions based on more than one conditions using if else. We use else if condition as follows -
|
||||
```cpp
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int score;
|
||||
std::cout<<"Enter your score: \n";
|
||||
std::cin>>score;
|
||||
cout << "Enter your score: \n";
|
||||
cin >> score;
|
||||
|
||||
if (score >= 90)
|
||||
std::cout<<"Top performance.";
|
||||
cout << "Top performance.";
|
||||
else if (score < 90 && score >= 70)
|
||||
std::cout<<"Good performance";
|
||||
cout << "Good performance";
|
||||
else if (score < 70 && score >= 45)
|
||||
std::cout<<"Average performance";
|
||||
cout << "Average performance";
|
||||
else if (score < 45 && score >= 30)
|
||||
std::cout<<"You can improve it.";
|
||||
cout << "You can improve it.";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
@ -142,11 +145,12 @@ Good performance
|
||||
### Another example of if...else if...else ladder
|
||||
Suppose we have the user input two numbers and we are going to display if either number is greater than the other. And if neither is greater than the other, then we print the statement "Both are equal".
|
||||
|
||||
In this scinerio we will need an if...else if...else ladder statement. The program will look like this :
|
||||
In this scenario, we will need an if...else if...else ladder statement. The program will look like this :
|
||||
|
||||
```
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int number1,number2;
|
||||
|
Reference in New Issue
Block a user