Attempting to calculate the value of the Interest variable using the conditions below, but having problems returning 0 or if I reorder the for loop, it returns 6471 for each account. It would be great if you could help me fix the for loop so that the right interest is displayed on 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;
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;
}
here is my modification:
#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;
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);
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;
system("pause");
return 0;
}