-2

I've made a code about Bank card, does it want silver or gold, then calculate the saving interests in 12 months,The output should be 112682512 if we input the saldoAwal = 100000000, but somehow it shows 101000000 What should I do?

I'm so confused because I've checked the calculations and still wrong, Help me? THANKS

#include <iostream>
#include <iomanip>
using namespace std;

struct Orang
{
    string namaNasabah = "";
    int jenisTabungan = 0;
    int saldoAwal = 0;
    int saldoBaru = 0;
};

Orang orang[100];

int n, i = 0;
float saldoMin, bunga, biayaAdministrasi;

void bungaTahunan(Orang orang[100]);

int main()
{

    cout << "Banyak nasabah : ";
    cin >> n;
    for(int i = 0; i < n ; i++)
    {
        cout << "Nama nasabah : ";
        cin >> orang[i].namaNasabah;
        cout << "Pilih silver atau gold? (1/2)"<<endl;
        cin >> orang[i].jenisTabungan;
        cout << "Saldo awal anda : ";
        cin >> orang[i].saldoAwal;

        bungaTahunan(&orang[i]);
    }

    cout << "nomor" << setw(20) << "nama" << setw(20) << "jenis tabungan" << setw(20) << "saldo awal" << setw(20) << "saldo akhir" << endl;
    for(int i = 0; i < n ; i++)
    {
        cout <<setprecision(10)<< i+1 << setw(20) << orang[i].namaNasabah << setw(20) << orang[i].jenisTabungan << setw(20) << orang[i].saldoAwal << setw(20) << orang[i].saldoBaru << endl;
    }



    return 0;
}

void bungaTahunan(Orang orang[100])
{
    if(orang[i].jenisTabungan == 1)
    {
        saldoMin = 10000000;
        bunga = 0.01;
        biayaAdministrasi = 10000;
    }
    else if (orang[i].jenisTabungan == 2)
    {
        saldoMin = 50000000;
        bunga = 0.02;
        biayaAdministrasi = 25000;
    }
    orang[i].saldoBaru = 0;
    for(int i = 0; i<12; i++)
    {
        if(orang[i].saldoAwal < saldoMin)
        {
            orang[i].saldoBaru += orang[i].saldoAwal + (orang[i].saldoAwal * bunga) - biayaAdministrasi;
        }
        else
        {
            orang[i].saldoBaru += orang[i].saldoAwal + (orang[i].saldoAwal * bunga);
        }
    }

}


Sorry if its in Indonesian Language.

  • You should not use float/double for money: use integers as a fraction of the currency. Why? because soon or late, float/double imprecision/rounding will cause you issues. – Adrian Maire Oct 13 '22 at 11:28
  • In function **void bungaTahunan(Orang orang[100])** there is no need to send a array of objects of **Orang** because your doing all those stuff on only one object. Also we don't know what you want to do, please add what you want to do and what you expect to happen. – Mahdy.n Oct 13 '22 at 11:44
  • [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jesper Juhl Oct 13 '22 at 11:55

1 Answers1

1

Last lines of your code is:

orang[i].saldoBaru = 0;

...

orang[i].saldoBaru = orang[i].saldoBaru + (orang[i].saldoBaru * orang[i].bunga);

saldoBaru is always 0, because "0 + 0*x" is 0

Adrian Maire
  • 14,354
  • 9
  • 45
  • 85