samedi 6 février 2016

For loop and conditional statement to calculate a value

Trying to Calculate a value for the Interest variable using the conditions i set below, but having trouble as it is returning 0, or if i rearrange the for loop it returns 6471 for each account. Would be great if you can help me fix the for loop so that the correct interest is shown in the console

#include <iostream>

using namespace std;



int main()

{

int AccountNumber[8] = { 1001, 7940, 4382, 2651, 3020, 7168, 6245, 9342 };

float Balance[8] = { 4254.40, 27006.25, 123.50, 85326.92, 657.0, 7423.34, 4.99, 107864.44 };

int DaysSinceDebited[8] = { 20, 35, 2, 14, 5, 360, 1, 45 };
int interest = 0;

//add your code here



cout << "Account Number\t" << "Balance\t\t" << "Days\t" << "Interest\t" << endl;
for (int i = 0; i < 8; i++)

    cout << AccountNumber[i] << "\t\t" << Balance[i] << "\t\t" << DaysSinceDebited[i] << "\t" << interest << "\t" << endl;

for (int i = 0; i < 8; i++)
    if (Balance[i] > 10000 || DaysSinceDebited[i] > 30)
        interest = (Balance[i] * 0.06);
    else
        interest = (Balance[i] * 0.03);



system("pause");
return 0;

}

Aucun commentaire:

Enregistrer un commentaire