program pemecah uang C++ (kasus 8 bab 4 diktat alpro)
Kasus 8 " Memecahkan Uang Rupiah"
Algoritma
- mendeklarasikan variabel uang
- membagi variabel uang dengan setiap mata uang
Deklarasi
- uang : interger
- u100, u50, u20, u10, u5, u2, u1, u500 : interger
Diskripsi
read(uang)
u100rb <- uang/100000;
sisa <- uang%100000;
u50rb <- sisa/50000;
sisa <- sisa%50000;
u20r <- sisa/20000;
sisa <- sisa%20000;
u10rb <- sisa/10000;
sisa <- sisa%10000;
u5rb <- sisa/5000;
sisa <- sisa%5000;
u2rb <- sisa/2000;
sisa <- sisa%2000;
u1rb <- sisa/1000;
sisa <- sisa%1000;
u5ratus <- sisa/500;
write(u100rb)
write(u50rb)
write(u20rb)
write(u10rb)
write(u5rb)
write(u1rb)
write(u5ratus)
codingannya..
#include<iostream>
using namespace std;
int main()
{
long uang,sisa;
int u100rb,u50rb,u20rb;
int u10rb,u5rb,u2rb,u1rb,u5ratus;
cout<<" Program Memecah Uang "<<endl;
cout<<"______________________________"<<endl;
cout<<" Masukan Jumlah Uang Rp."; cin>>uang;
u100rb=uang/100000;
sisa=uang%100000;
u50rb=sisa/50000;
sisa=sisa%50000;
u20rb=sisa/20000;
sisa=sisa%20000;
u10rb=sisa/10000;
sisa=sisa%10000;
u5rb=sisa/5000;
sisa=sisa%5000;
u2rb=sisa/2000;
sisa=sisa%2000;
u1rb=sisa/1000;
sisa=sisa%1000;
u5ratus=sisa/500;
cout << endl <<endl;
cout <<" Uang anda Rp. "<<uang<<endl;
cout <<" Terdiri dari : "<<endl;
cout <<" _______________ "<<endl;
if (u100rb > 0)
cout<<u100rb<<" lembar Rp.100.000"<<endl<<endl;
if (u50rb > 0)
cout<<u50rb<<" lembar Rp.50.000"<<endl<<endl;
if (u20rb > 0)
cout<<u20rb<<" lembar Rp.20.000"<<endl<<endl;
if (u10rb > 0)
cout<<u10rb<<" lembar Rp.10.000"<<endl<<endl;
if (u5rb > 0)
cout<<u5rb<<" lembar Rp.5.000"<<endl<<endl;
if (u2rb > 0)
cout<<u2rb<<" lembar Rp.2.000"<<endl<<endl;
if (u1rb > 0)
cout<<u1rb<<" lembar Rp.1.000"<<endl<<endl;
if (u5ratus > 0)
cout<<u5ratus<<" keping Rp.500"<<endl<<endl;
}
Raptor :
EmoticonEmoticon