In this programming, still within the scope of "C++ Looping Basics", if we observe the program below is still very simple, because it involves very few types of data types, besides that the statements are also still simple, well it is natural to start something big or complex must be started first from the small. because in the concept of programming, although all things related to programming are important, the most basic and main thing is Understanding the Schema / Pattern of an Object. because this is the initial capital to start an analysis, so that our brains get used to this, we need to train them with small or simple things first.
C++ Simple Payment Installment
Source code:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
/**
*bundet.com
*Copyright RIYADI ABDUL AZIS
*Cicilan Pembayaran Sederhana
*/
void main() {
int x, cicilan, jumlah, harga, kembali;
char jawab;
clrscr();
cout << "Budi membeli Flashdisk Jono\n";
cout << "Harga Flashdisk : "; cin >> harga;
cout << endl;
x = 1;
jumlah = 0;
while (jumlah < harga) {
cout << "Cicilan ke-" << x << " : "; cin >> cicilan;
x++;
jumlah = jumlah + cicilan;
}
cout << endl;
cout << "Total cicilan : " << jumlah << endl;
cout << "Harga Flashdisk : " << harga << endl;
if (jumlah > harga) {
kembali = jumlah - harga;
cout << "Kembalian : " << kembali << endl;
}
cout << "\nLUNAS!!!\n\n";
cout << "\n\nklik <ENTER> untuk exit";
getch();
}
If previously in the same discussion, the number of installments was not determined, well this time I will complete it with the limit of the number of installments that will be agreed upon, just for more details below:
C++ Installment Payment Determined
Source code:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
/**
*bundet.com
*Cicilan Pembayaran Ditentukan
*/
void main() {
int x, cicilan, jumlah, harga, kembali, jumlah_cicilan, cicilan_terakhir;
char jawab;
clrscr();
cout << "Budi membeli Flashdisk Jono\n";
cout << "Harga Flashdisk : "; cin >> harga;
cout << "Jumlah cicilan : "; cin >> jumlah_cicilan;
cout << endl;
x = 1;
jumlah = 0;
while (jumlah < harga && x <= jumlah_cicilan) {
if ( x == jumlah_cicilan) {
cicilan_terakhir = harga - jumlah;
cout << "Cicilan ke-" << x << " : " << cicilan_terakhir << endl;
break;
}
else {
cout << "Cicilan ke-" << x << " : "; cin >> cicilan;
x++;
jumlah = jumlah + cicilan;
}
}
cout << "\nLUNAS!!!\n\n";
cout << "\n\nklik <ENTER> untuk exit";
getch();
}
Hope this is useful and happy learning