if else

hi,i am sbahat i read if else structure.and i want to practice it.plz give me example program for practice.
 
  if else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int main()
{
    std::cout << "Enter a number: " << std::flush;
    int x;
    std::cin >> x;
    if(x < 0)
    {
        std::cout << "You entered a negative number" << std::endl;
    }
    else if(x > 0)
    {
        std::cout << "You entered a positive number" << std::endl;
    }
    else
    {
        std::cout << "You entered zero" << std::endl;
    }
}
Notice that else if {} is identical to else { if {} }.
Topic archived. No new replies allowed.