Control Structures, If Else and Switch Case Statements in C++

 #include<iostream>

using namespace std;

int main()
{
    int age;
    cout<<"Tell me your age"<<endl;
    cin>>age;

    //  Selection control structure : If else-if else ladder
    if((age<18) && (age>0))
    {
        cout<<"You can not come to my party"<<endl;
    }
    else if(age==18)
    {
        cout<<"You are a kid and you will get a kid pass to the party"<<endl;
    }
    else if(age<1)
    {
        cout<<"You are not yet born"<<endl;
    }
    else
    {
        cout<<"You can come to the party"<<endl;
    }


    //  Selection control structure : Switch case statements
    switch(age)
    {
    case 18: {
        cout<<"You are 18"<<endl;
        break;
    }
    case 22: {
        cout<<"You are 22"<<endl;
        break;
    }
    case 2: {
        cout<<"You are 2"<<endl;
        break;
    }
    default:
        cout<<"No Special Cases"<<endl;
        break;
    }
    cout<<"Done with Switch case"<<endl;
    return 0;
}
//OUTPUT:
//Tell me your age
// 18
// You are a kid and you will get a kid pass to the party
// You are 18
// Done with Switch case

Comments

Popular posts from this blog

Basic Input/Output & More in C++