Fix some indentation and change some typo (#22017)

pull/22027/head^2
fadelpamungkas 2018-11-18 10:13:05 +07:00 committed by Christopher McCormack
parent 1606de6c51
commit d93ad2c00b
1 changed files with 18 additions and 14 deletions

View File

@ -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;
if(score>=90)
std::cout<<"Top performance.";
else if(score<90 && score>=70)
std::cout<<"Good performance";
else if(score<70 && score>=45)
std::cout<<"Average performance";
else if(score<45 && score>=30)
std::cout<<"You can improve it.";
cout << "Enter your score: \n";
cin >> score;
if (score >= 90)
cout << "Top performance.";
else if (score < 90 && score >= 70)
cout << "Good performance";
else if (score < 70 && score >= 45)
cout << "Average performance";
else if (score < 45 && score >= 30)
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;
@ -155,11 +159,11 @@ int main()
cout << "Enter second number: \n";
cin >> number2;
if(number1 > number2) // Checks if the first number is greater than the second number
if (number1 > number2) // Checks if the first number is greater than the second number
{
cout << "Number 1 is greater.";
}
else if(number2 > number1) // Checks if the second number is greater than the first number
else if (number2 > number1) // Checks if the second number is greater than the first number
{
cout << "Number 2 is greater.";
}