Kembali Lagi Gan Belajar membuat program C++. Kali ini ane mau ngasih tw ni cara membuat program yang berisi perulangan. Mumpung ane juga baru ngerti mebuat program kayak gini, itupun di kasih tau sama temen ane yang satu kelas.. hehehe Tank's Friend.. Dari pada ane ngerti sendiri, mending ane bagi - bagi ilmu dah sekarang.. OK, dari pada curhat - curhat gini, mending langsung ajak yux Gan ke TKP, ane disini ngambil contoh membuat rumus matematika Dasar :
==================================================
#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int no;
float a,b,c;
char ans;
do {
clrscr();
cout<<"==============================="<<endl;
cout<<" mr. kadoel Program "<<endl;
cout<<"==============================="<<endl;
cout<<endl;
cout<<" =*= PILIHAN PROGRAM =*= "<<endl<<endl;
cout<<" 1. Penjumlahan "<<endl;
cout<<" 2. Pengurangan "<<endl;
cout<<" 3. Perkalian "<<endl;
cout<<" 4. Pembagian "<<endl;
cout<<" 5. Tabel Perkalian"<<endl;
cout<<" 6. Akar Kuadrat"<<endl<<endl;
cout<<endl;
cout<<"Masukkan Pilihan Program = "; cin>>no;
cout<<endl;
if(no==1)
{
clrscr();
cout<<"-------------------------------"<<endl;
cout<<" =*= Program Penjumlahan =*= "<<endl;
cout<<"-------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Nilai a = "; cin>>a;
cout<<"Masukkan Nilai b = "; cin>>b;
cout<<endl;
c=a+b;
cout<<"Hasil Penjumlahan = "<<c<<endl;
cout<<endl;
cout<<"-------------------------------";
cout<<endl; cout<<endl;
}
if(no==2)
{
clrscr();
cout<<"-------------------------------"<<endl;
cout<<" =*= Program Pengurangan =*= "<<endl;
cout<<"-------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Nilai a = "; cin>>a;
cout<<"Masukkan Nilai b = "; cin>>b;
cout<<endl;
c=a-b;
cout<<"Hasil Pengurangan = "<<c<<endl;
cout<<endl;
cout<<"-------------------------------";
cout<<endl; cout<<endl;
}
if (no==3)
{
clrscr();
cout<<"-------------------------------"<<endl;
cout<<" =*= Program Perkalian =*= "<<endl;
cout<<"-------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Nilai a = "; cin>>a;
cout<<"Masukkan Nilai b = "; cin>>b;
cout<<endl;
c=a*b;
cout<<"Hasil Perkalian = "<<c<<endl;
cout<<endl;
cout<<"-------------------------------";
cout<<endl; cout<<endl;
}
if (no==4)
{
clrscr();
cout<<"------------------------------"<<endl;
cout<<" =*= Program Pembagian =*= "<<endl;
cout<<"------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Nilai a = "; cin>>a;
cout<<"Masukkan Nilai b = "; cin>>b;
cout<<endl;
cout.setf(ios::fixed);
cout.precision(2);
c=a/b;
cout<<"Hasil Pembagian = "<<c<<endl;
cout<<endl;
cout<<"------------------------------"<<endl;
cout<<endl; cout<<endl;
}
if (no==5)
{
clrscr();
cout<<"------------------------------"<<endl;
cout<<"=*= Tabel Perkalian 1 - 10 =*="<<endl;
cout<<"------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Angka Perkalian = "; cin>>c ;
cout<<endl;
for (a=c; a<=c; a++)
{
for (b=1; b<= 10;++b)
cout<<a<<" x "<<b<<" = "<<a*b<<"\n"<<endl;
cout<<"------------------------------"<<endl;
}
cout<<endl<<endl;
}
if (no==6)
{
clrscr();
cout<<"------------------------------"<<endl;
cout<<" =*= Akar Kuadrat =*= "<<endl;
cout<<"------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Angka : "; cin>>a;
cout<<endl<<endl;
cout<<"Akar Dari "<<a<<" = "<<sqrt(a)<<endl<<endl;
cout<<"------------------------------"<<endl;
cout<<endl<<endl;
}
cout<<"Apakah Andan Ingin Mencoba Program Yang Lain ? [Y/N] = " ;
cin>>ans;
}
while (ans=='y'||ans=='Y');
cout<<endl; cout<<endl;
cout<<"=*= Terimakasih =*= "<<endl;
cout<<endl;
cout<<" By : mr. kadoel "<<endl;
cout<<" --------------- "<<endl;
getch();
}
==================================================
Ini Hasil Print Outnya :
Atau Bisa Download Source Codenya di
Atau Bisa Juga Download Source Code untuk Rumus Bangun Datar di
Semoga Bermanfaat Gan...
Widget by [ Free Widget ]
0 comments:
Posting Komentar