1.if pertama
#include <iostream.h>
#include <conio.h>
void main()
{
int nilai;
cout<<"Masukkan nilai : ";
cin>>nilai;
if(nilai>50)
{
cout<<"Nilai yang anda masukkan"<<endl
<<"lebih dari 50";
}
getch();
}
3.if bertumpuk
#include <iostream.h>
#include <conio.h>
void main()
{
int nilai;
cout<<"Masukkan nilai : ";
cin>>nilai;
if(nilai>80)
{
cout<<"Nilai anda A";
}
else if(nilai>60)
{
cout<<"nilai anda B";
}
else if(nilai>40)
{
cout<<"nilai anda C";
}
getch();
}
4. hari
#include <iostream.h>
#include <conio.h>
void main()
{
int kode;
cout<<"masukkan kode (1-7):";
cin>>kode;
if(kode==1)
{
cout<<"kode "<<kode<< " = hari senin";
}
else if(kode==2)
{
cout<<"kode"<<kode<< " = hari selasa";
}
else if(kode==3)
{
cout<<"kode "<<kode<< " =hari rabu";
}
else if(kode==4)
{
cout<<"kode "<<kode<< " =hari kamis";
}
else if(kode==5)
{
cout<<"kode "<<kode<< " =hari jumat";
}
else if(kode==6)
{
cout<<"kode "<<kode<< " =hari sabtu";
}
else if(kode==7)
{
cout<<"kode "<<kode<< " =hari minggu";
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
char kode;
cout<<"masukkan kode (A-G):";
cin>>kode;
if(kode=='A')
{
cout<<"kode "<<kode<< " = hari senin";
}
else if(kode=='B')
{
cout<<"kode"<<kode<< " = hari selasa";
}
else if(kode=='C')
{
cout<<"kode "<<kode<< " =hari rabu";
}
else if(kode=='D')
{
cout<<"kode "<<kode<< " =hari kamis";
}
else if(kode=='E')
{
cout<<"kode "<<kode<< " =hari jumat";
}
else if(kode=='F')
{
cout<<"kode "<<kode<< " =hari sabtu";
}
else if(kode=='G')
{
cout<<"kode "<<kode<< " =hari minggu";
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
int kode;
cout<<"masukkan kode (1-7):";
cin>>kode;
switch(kode)
{
case 1 : cout<<"hari senin";break;
case 2 : cout<<"hari selasa";break;
case 3 : cout<<"hari rabu";break;
case 4 : cout<<"hari kamis";break;
case 5 : cout<<"hari jumat";break;
case 6 : cout<<"hari sabtu";break;
case 7 : cout<<"hari minggu";break;
}
getch();
}
Perkalian penjumlahan
#include <iostream.h>
#include <conio.h>
void main()
{
int bil1,bil2,hasil;
char kode;
cout<<"masukkan bilangan pertama:";
cin>>bil1;
cout<<"masukkan bilangan kedua:";
cin>>bil2;
cout<<"masukkan kode:";
cin>>kode;
switch(kode)
{
case '+' :
hasil=bil1+bil2;
cout<<"hasil penjumlahan ="<<hasil;break;
case '*' :
hasil=bil1*bil2;
cout<<"hasil rekalian ="<<hasil;break;
}
getch();
}
Tidak ada komentar:
Posting Komentar