waktu(clocklink.com)

01 December 2014

Tutorial C++ : How to select channel

In this session, i will discuss very simple program, it's about how to select channel. I use C++ to make this program and use switch case to solve this problem.

Okey,let's see the source code :


#include<iostream>

using namespace std;

int main()
{
    int channel;
    cout<<"input number of channel: ";
    cin>>channel;
   
    switch(channel)
    {
                   case 1:
                   cout<<"TVRI\n";
                   break;
                   case 2:
                   cout<<"RCTI\n";
                   break;
                   case 3:
                   cout<<"SCTV\n";
                   break;
                   case 4:
                   cout<<"ANTV\n";
                   break;
                   case 5:
                   cout<<"METRO TV\n";
                   break;
                   default :
                   cout<<"no signal in that channel\n";
                   break;
                 
                 
    }
system("pause");
return 0;
}

---***-----
this is the analysis of codes:
#include<iostream>              //is library to determine cin(input) and cout(output)
int main()                              //this is the main program that will be execute
int channel;                                   //type is integer(number) and the name of variable is channel
cout <<"input number of channel: ";     //display "input number of channel: " to screen


cin>>channel;                              //if user enters number, the program scan that number as "channel"
switch(channel)                           //the variable that determines result is channel
case 1:
                   cout<<"TVRI\n";
                   break;                         //if input is 1,the output is TVRI
case 2:
                   cout<<"RCTI\n";
                   break;                         //if input is 2,the output is RCTI
case 3:
                   cout<<"SCTV\n";
                   break;                         //if input is 3,the output is SCTV
case 4:
                   cout<<"ANTV\n";     //if input is 4,the output is ANTV
                   break;
case 5:
                   cout<<"METRO TV\n";
                   break;                         //if input is 5,the output is METRO TV
default :
                   cout<<"tidak ada sinyal station tv di channel itu\n";
                   break;                         //if input is not between 1-5, output is "no signal in that channel"

system ("PAUSE");             //system will pause until user press a key
return 0;                        //it will end main function and the return value is 0(the program run correctly)

}


run this program and this is the result:


yeah,you got it?