Lecture 19
Conditional Statements (Decision Making)
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int Marks;
cout<<"Enter marks. : ";
cin>>Marks;
if (Marks >
40) cout <<"Congraduiations !
you passed! ";
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[])
{
char ch;
int num1, num2;
cout<<"Enter number one : ";
cin>>num1;
cout<<"Enter number two : ";
cin>>num2;
cout<<"Are you addition or subtract in between two number \n
Please Enter (+ or -) : ";
cin>>ch;
if (ch == '+')
{
cout
<<"Addition : " << num1+num2;
}
if (ch == '-')
{
cout
<<"Subtraction : "<< num1-num2;
}
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10