Lecture 18
Conditional Statements (Decision Making)
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int num;
cout<<"Enter a number less than 10 : ";
cin>>num;
if (num <= 10)
cout <<"What
an obedient servant you are! ";
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int num;
cout<<"Enter a number 1 to 5 : ";
cin>>num;
if (num < 1)
cout
<<"Your number less then one ";
if (num == 1)
cout
<<"Your number is \" One \" ";
if (num == 2)
cout
<<"Your number is \" Two \" ";
if (num == 3)
cout <<"Your number is \"
Three \" ";
if (num == 4)
cout
<<"Your number is \" Four \" ";
if (num == 5)
cout
<<"Your number is \" Five \" ";
if (num > 5)
cout
<<"Your number large of five
";
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10