Here's the problem.
A group of students are members of a club that travels annually to different locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they are planning a trip to Eindhoven.
The group agrees in advance to share expenses equally, but it is not practical to share every expense as it occurs. Thus individuals in the group pay for particular things, such as meals, hotels, taxi rides, and plane tickets. After the trip, each student's expenses are tallied and money is exchanged so that the net cost to each is the same, to within one cent. In the past, this money exchange has been tedious and time consuming. Your job is to compute, from a list of expenses, the minimum amount of money that must change hands in order to equalize (within one cent) all the students' costs.
Input
Standard input will contain the information for several trips. Each trip consists of a line containing a positive integer n denoting the number of students on the trip. This is followed by n lines of input, each containing the amount spent by a student in dollars and cents. There are no more than 1000 students and no student spent more than $10,000.00. A single line containing 0 follows the information for the last trip.
Output
For each trip, output a line stating the total amount of money, in dollars and cents, that must be exchanged to equalize the students' costs.
Sample Input
3
10.00
20.00
30.00
4
15.00
15.01
3.00
3.01
0
Sample Output
$10.00
$11.99
My code works for some test cases, but fails at others. I think it's because of a precision error in the float. However, I can't find the error.
For example,
Input:
4
9999.1
9999.1
9999.0
9999.1
Output:
$0.06
However, the output should be $0.07
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define MAX 1000
using namespace std;
float money[MAX];
int main(){
int numOfStudents;
int i; // loop counter
double average; // of the costs
double negDiff, posDiff; // |amount-average|
double minDiff;
float total; // all the costs added together
while(scanf("%d", &numOfStudents) == 1){
if(numOfStudents == 0){
break;
}
memset(money, 0, sizeof(money));
total = 0;
for(i = 0; i < numOfStudents; i++){ // scan for the cost of each student - input into array
double m;
scanf("%lf", &m);
money[i] = m;
total += m;
}
average = total/numOfStudents;
negDiff = 0;
posDiff = 0;
for(i = 0; i < numOfStudents; i++){ // find the difference between average and each cost -> add together
if(money[i] > average){
posDiff += (long) ((money[i] - average) * 100.0) / 100.0;
}
else{
negDiff += (long) ((average - money[i]) * 100.0) / 100.0;
}
}
minDiff = 0;
if(posDiff > negDiff){ // find the minimum value for all to equal
minDiff = negDiff;
}
else{
minDiff = posDiff;
}
printf("$%.2lf\n", minDiff);
}
return 0;
}
If you are chopping the positive and negative differences upto 2 decimal places, chop the average also. This gives the result you are expecting (simplified working code)
#include <stdio.h>
int main() {
int n, i;
double average, negDiff, posDiff, minDiff, total;
while (scanf("%d", &n) == 1 && n != 0) {
double money[n];
total = 0.0;
for (i = 0; i < n; i++) {
scanf("%lf", &money[i]);
total += money[i];
}
average = (long) ((total / n) * 100.0) / 100.0;
negDiff = posDiff = 0.0;
for (i = 0; i < n; i++) {
if (money[i] > average)
posDiff += (long) ((money[i] - average) * 100.0) / 100.0;
else
negDiff += (long) ((average - money[i]) * 100.0) / 100.0;
}
minDiff = posDiff > negDiff ? negDiff : posDiff;
printf("$%.2lf\n", minDiff);
}
return 0;
}
Input
3
10.00 20.00 30.00
4
15.00 15.01 3.00 3.01
4
9999.1 9999.1 9999.0 9999.1
0
Output
$10.00
$11.99
$0.07
See http://ideone.com/cxhvlL
Well... you might be right. You really shouldn't be reading the money in as floats.
scanf ("%d.%d", &dollars, &pennies);
int m = dollars * 100 + pennies;
As for solving the problem in general, just make sure you stick to integral division
int average = total / numStudents;
int leftover = total % numStudents;
// numStudents - leftover students need to have paid $average
// leftover students need to have paid $average + 1
int paid = 0;
int recieved = 0;
for (int i = 0; i < numStudents; ++i)
{
// Since we start with the lowest amount owed, money array needs to have been
// sorted such that the student who paid the least comes first.
owed_money = average;
if (i > numStudents - leftover)
owed_money += 1;
if (money[i] < owed_money)
paid += owed_money - money[i];
else if (money[i] > owed_money)
recieved += money[i] - owed_money;
}
assert (paid == recieved);
Maybe there's a better way to do it? In any case, it's a hard problem, but I can promise your solution shouldn't contain any floating point arithmetic.
Calculate the average only down to cents rest needs to be dropped. That means we will be putting x cents in the side pot and since x is going to be less than n, in the end even if you distribute it only few will get and they will be atmost one cent more than others. So they are all with in the cents.
Now with that said. Here is the simple code for that
int main( )
{
int n;
cin >> n;
while( n ) {
vector<double> v;
while( n-- ) {
double x;
cin >> x;
v.push_back( x );
}
double avg = accumulate( begin(v), end(v), 0.0 ) / v.size();
avg = ((int)(avg*100))/100.00;
double exchange = 0;
for ( auto x : v ) { if ( x < avg ){ exchange += avg - x; } }
cout << exchange << endl;
cin >> n;
}
return 0;
}
and for this input
3
10.00
20.00
30.00
4
15.00
15.01
3.00
3.01
4
9999.1
9999.1
9999.0
9999.1
0
output is
10
11.99
0.07
Related
Running the following code I expect to receive such an output:
Desired output:
Car Hours Charge
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
But the results comes out as follows:
Actual output:
Car Hours Charge
1 2 2
2 4 2.5
3 2e+01 10
Any suggestions that can guide me to use the correct floating point comparison and using setprecision correctly is welcome.
int main()
{
double hour[3];
double charge[3];
double sum_hour = 0;
double sum_charge = 0;
for (int i = 0; i < 3; i++)
{
cout<<"Enter the hours for car No. "<<i<<": ";
cin>>hour [i];
if (hour [i] <= 3)
{charge [i] = 2.00;}
if (hour [i] > 3 && hour [i] < 24)
{charge [i] = (2.00 + (ceil(hour [i] -3))*0.5);}
if (hour [i] == 24)
{charge [i] = 10.00;}
sum_hour = sum_hour + hour [i];
sum_charge = sum_charge + charge [i];
}
cout<<"Car"<<setw(10)<<"Hours"<<setw(10)<<"Charge"<<endl;
for (int i = 0; i < 3; i++)
{
cout<<i+1<<setw(10)<<setprecision(1)<<hour[i]<<setw(10)<<setprecision(2)<<charge[i]<<endl;
}
cout<<"TOTAL"<<setw(6)<<sum_hour<<setw(10)<<sum_charge<<endl;
}
std::setprecision by default sets the total number of significant digits that are shown (ie. including the ones before the decimal point).
To set the number of digits shown after the decimal point, use std::fixed :
std::cout << std::fixed << std::setprecision(2) << 24.0;
will display :
24.00
You need function fixed to make cout write digits when it got only '0'.
So use it like this:
cout << fixed;
cout<<i+1<<setw(10)<<setprecision(1)<<hour[i]<<setw(10)<<setprecision(2)<<charge[i]<<endl;
The question is to find the number of interesting numbers lying between two numbers. By the interesting number, they mean that the product of its digits is divisible by the sum of its digits.
For example: 459 => product = 4 * 5 * 9 = 180, and sum = 4 + 5 + 9 = 18; 180 % 18 == 0, hence it is an interesting number.
My solution for this problem is having run time error and time complexity of O(n2).
#include<iostream>
using namespace std;
int main(){
int x,y,p=1,s=0,count=0,r;
cout<<"enter two numbers"<<endl;
cin>>x>>y;
for(int i=x;i<=y;i++)
{
r=0;
while(i>1)
{
r=i%10;
s+=r;
p*=r;
i/=10;
}
if(p%s==0)
{
count++;
}
}
cout<<"count of interesting numbers are"<<count<<endl;
return 0;
}
If s is zero then if(p%s==0) will produce a divide by zero error.
Inside your for loop you modify the value of i to 0 or 1, this will mean the for loop never completes and will continuously check 1 and 2.
You also don't reinitialise p and s for each iteration of the for loop so will produce the wrong answer anyway. In general limit the scope of variables to where they are actually needed as this helps to avoid this type of bug.
Something like this should fix these problems:
#include <iostream>
int main()
{
std::cout << "enter two numbers\n";
int begin;
int end;
std::cin >> begin >> end;
int count = 0;
for (int number = begin; number <= end; number++) {
int sum = 0;
int product = 1;
int value = number;
while (value != 0) {
int digit = value % 10;
sum += digit;
product *= digit;
value /= 10;
}
if (sum != 0 && product % sum == 0) {
count++;
}
}
std::cout << "count of interesting numbers are " << count << "\n";
return 0;
}
I'd guess the contest is trying to get you to do something more efficient than this, for example after calculating the sum and product for 1234 to find the sum for 1235 you just need to add one and for the product you can divide by 4 then multiply by 5.
Apparently I was actually suppose to create an array that randomly assigns birthdays over many trials (5000). It's then suppose to count up each time there is at least 2 birthdays for 2 - 50 people and divide the outcome by 5,000 to get the approximate probability. I believe I have my loops messed up and would like some feedback. Not code, I would like to understand exactly what is going wrong and how I messed it up.
int main()
{
const int trials(5000);
double total;
int count(0), birthdays[49];
srand(time(NULL));
for (int i = 2; i <= 50; i++)
{
for (int k = 0; k < trials; k++)
{
fillUp(birthdays, 49);
for (int j = i + 1; j <= 50; j++)
{
if (birthdays[i] == birthdays[j])
{
count += 1;
}
}
}
total = count / 5000.0;
cout << "For " << i << " the probability is " << total << endl;
}
return 0;
}
void fillUp(int birthdays [], int size)
{
for (int i = 0; i < size; i++)
{
birthdays[i] = rand() % 365 + 1;
}
}
Output:
For 2 the probability is 0.1286
For 3 the probability is 0.2604
...
...
For 49 the probability is 3.9424
For 50 the probability is 3.9424
Any help would be really appreciated.
The problem isn't the C++ code; you just have a typo in your math. It should be:
power = (num * (num - 1.0) / 2.0);
chance = 1.0 - pow(constant, power);
You are calculating 364/365 ≈ 0.0027 to the power of some large number, which results in a number only very slightly above zero. When rounded to the requested output precision, this results in zero.
You may know the formula, but your code is not implementing it correctly. Here is some C code that implements the formula correctly:
#include <stdio.h>
int main(void) {
double p;
int ii;
int people;
for (people = 3; people < 50; people++) {
p = 1;
for (ii = 1; ii < people; ii++) {
p *= (365.0 - ii) / 365.0;
}
printf("for %d people, probability is %.4f\n", people, 1 - p);
}
return 0;
}
This results in the following output:
for 1 people, probability is 0.0000
for 2 people, probability is 0.0027
for 3 people, probability is 0.0082
for 4 people, probability is 0.0164
for 5 people, probability is 0.0271
for 6 people, probability is 0.0405
for 7 people, probability is 0.0562
for 8 people, probability is 0.0743
for 9 people, probability is 0.0946
for 10 people, probability is 0.1169
for 11 people, probability is 0.1411
for 12 people, probability is 0.1670
for 13 people, probability is 0.1944
for 14 people, probability is 0.2231
for 15 people, probability is 0.2529
for 16 people, probability is 0.2836
for 17 people, probability is 0.3150
for 18 people, probability is 0.3469
for 19 people, probability is 0.3791
for 20 people, probability is 0.4114
for 21 people, probability is 0.4437
for 22 people, probability is 0.4757
for 23 people, probability is 0.5073
for 24 people, probability is 0.5383
for 25 people, probability is 0.5687
for 26 people, probability is 0.5982
for 27 people, probability is 0.6269
for 28 people, probability is 0.6545
for 29 people, probability is 0.6810
Leading to the familiar result that "the chance is > 50% with just 23 people".
In essence you have created a new question, so I will create a new answer. Right now you keep changing the birthdays while you are looping over them; this is why things don't work. You need two nested loops to test for equal birthdays (or if you are smart you sort them, then only check adjacent ones. It is probably faster with n = 50.)
You also need to start testing at the first birthday (your array is base 0 - but you start with i = 2). And for each trial, you can see how many people you need to compare before you have a match. The correct code will look something like this (note that I run 5000 trials for each number of people in the room; you could be more efficient by checking for a match when you have 3,4,5... people based on the same sample, but then there would be some correlation in the sampling).
EDITED - tested this code, seems to compile and run OK. Results look close to expected values.
#include <iostream>
void fillUp(int birthdays [], int size)
{
for (int i = 0; i < size; i++)
{
birthdays[i] = rand() % 365 + 1;
}
}
int main(void) {
int birthdays[50];
int trials = 5000;
int flag;
double total;
int collisions[50];
// number of people "in the room"
for (int i = 2; i < 50; i++)
{
collisions[i] = 0;
// do 5000 trials:
for (int t = 0; t < trials; t++)
{
fillUp(birthdays, i);
flag = 0;
// compare all pairs (j,k):
for (int j = 0; j < i - 1 && flag == 0; j++)
{
for (int k = j + 1; k < i && flag == 0; k++ )
{
if (birthdays[k] == birthdays[j])
{
collisions[i]++;
flag = 1;
}
}
}
}
total = collisions[i] / 5000.0;
std::cout << "For " << i << " people in the room the probability is " << total << std::endl;
}
return 0;
}
Note - I did not have a chance to compile / test this; it should be right "in essence". Let me know if it gives a problem.
I am trying to count the amount of dollar and coin denominations in a grand total by using a series of while loops. When I get down to the coins however, I am off by a penny. When I enter say 99.95, I get the output 3 quarters, 1 dime, 1 nickel, and 4 pennies. I've narrowed the problem down to a floating point accuracy issue. However all the solutions I've researched haven't been applicable in my situation. Any pointers?
#include <iostream>
using namespace std;
int main()
{
float amount;
cout<<"enter amount" << endl;
cin>>amount;
int pennies=0, nickels=0, dimes=0, quarters=0, ones=0, fives=0,
tens=0,
twenties=0, fifties=0, hundreds=0;
while (amount >= 100)
{
hundreds = hundreds +1;
amount = amount - 100;
}
while (amount >= 50)
{
fifties = fifties +1;
amount = amount - 50;
}
while (amount >= 20)
{
twenties = twenties +1;
amount = amount - 20;
}
while (amount >= 10)
{
tens = tens +1;
amount = amount - 10;
}
while (amount >= 5)
{
fives = fives +1;
amount = amount - 5;
}
while (amount >= 1)
{
ones = ones +1;
amount = amount - 1;
}
while (amount >= .25)
{
quarters = quarters +1;
amount = amount - .25;
}
while (amount >= .10)
{
dimes = dimes +1;
amount = amount - .10;
}
while (amount >= .05)
{
nickels = nickels +1;
amount = amount - .05;
}
while (amount >= .01)
{
pennies = pennies +1;
amount = amount - .01;
}
cout<<endl<<"pennies:"<< pennies;
cout<<endl<<"nickels:"<<nickels;
cout<<endl<<"dimes:"<<dimes;
cout<<endl<<"quarters:"<<quarters;
cout<<endl<<"ones:"<<ones;
cout<<endl<<"fives:"<<fives;
cout<<endl<<"tens:"<<tens;
cout<<endl<<"twenties:"<<twenties;
cout<<endl<<"fifties:"<<fifties;
cout<<endl<<"hundreds:"<<hundreds<<endl;
return 0;
}
Don't use floating point in cases where you need exact values. 99.95 can't be exactly represented in a float or double, a bit like 1/3 can't be exactly represented using a finite number of normal decimal digits.
As Doug T. suggested, you can use an integer to hold the number of pennies. When the user types 123.45, read it as two integers, and then store it as 12345 pennies, not as 123.45 dollars.
In this case, you can also try to change your last while (amount >= .01) to something like while (amount >= .005). It's not a solution that can be generally recommended, and if this is a real-life bank application you really should avoid it, but it will help against at least some of the errors.
You should be using fixed-point values in this case, not floating-point.
Although people think of money in terms of dollars, which aren't exact, money is measured in cents, which are exact. Just count the number of cents, divide by 100 to get the dollar amount, and take the modulus to get the cent amount. Floating-point is not the proper tool in this case.
Binary floating point numbers cannot, in general, represent fractional decimal values, even if the total number of decimals is small. For example, 0.1 cannot be represented exactly.
To deal with exact values different approaches exist which all amount to using a different base than 2. Depending on tge specific needs the approaches are more or less involved. The easieast approach for your case is to use a fixed precision instead of a variable precision. To compute with fixed precision you'd just use an integer which represents the value you actually want multiplied by a suitable power of 10. Depending on the amount of computations you do you can either package the logic into a class or distribute it throughout the code. In a "real" application I'd package it into a class, in an assignment (homework, interview, etc.) I'd probably just apply the logic directly to an int.
Here's the fixed code, I used TJD's advice and instead of using .01 i used .0099 instead. For my problem that seems to work, thanks guys!
#include <iostream>
using namespace std;
int main()
{
float amount;
cout<<"enter amount" << endl;
cin>>amount;
int pennies=0, nickels=0, dimes=0, quarters=0, ones=0, fives=0,
tens=0,
twenties=0, fifties=0, hundreds=0;
float p = .0099, n = .0499, d = .099, q = .2499;
while (amount >= 100)
{
hundreds = hundreds +1;
amount = amount - 100;
}
while (amount >= 50)
{
fifties = fifties +1;
amount = amount - 50;
}
while (amount >= 20)
{
twenties = twenties +1;
amount = amount - 20;
}
while (amount >= 10)
{
tens = tens +1;
amount = amount - 10;
}
while (amount >= 5)
{
fives = fives +1;
amount = amount - 5;
}
while (amount >= 1)
{
ones = ones +1;
amount = amount - 1;
}
while (amount >= q)
{
quarters = quarters +1;
amount = amount - q;
}
while (amount >= d)
{
dimes = dimes +1;
amount = amount - d;
}
while (amount >= n)
{
nickels = nickels +1;
amount = amount - n;
}
while (amount >= p)
{
pennies = pennies +1;
amount = amount - p;
}
cout<<endl<<"pennies:"<< pennies;
cout<<endl<<"nickels:"<<nickels;
cout<<endl<<"dimes:"<<dimes;
cout<<endl<<"quarters:"<<quarters;
cout<<endl<<"ones:"<<ones;
cout<<endl<<"fives:"<<fives;
cout<<endl<<"tens:"<<tens;
cout<<endl<<"twenties:"<<twenties;
cout<<endl<<"fifties:"<<fifties;
cout<<endl<<"hundreds:"<<hundreds<<endl;
return 0;
}
I have a homework assignment which I feel I am close to getting right. The assignment is as follows:
Banks loan money to each other. In tough economic times, If a bank goes bankrupt it may not be able to pay back the loan. A bank's total assets is its current balance plus its loans to other banks. Figure 8.1 ( attached image ) is a diagram tat shows five banks. The banks' current balances are: 25, 125, 175, 75 and 181 million dollars, respectively. The directed edge from node 1 to node 2 indicates that bank 1 loans 40 mill to bank 2.
If a banks total asset is under a certain limit, the bank is considered unsafe. If a bank is unsafe, the money it borrowed cannot be returned to the lender and the lender cannot count the loan in its total assets. Consequently, the Lender may also be unsafe.
Write a program to find all unsafe banks. Your program reads the input as follows. It first reads two integers, n and limit, where n indicates the number of banks and limit is the minimum assets for keeping a bank safe. It then reads n lines that describe the information for n banks with id from 0 to n-1. The first number in the line is the bank's balance. The second number indicates the number of that borrowed money from the bank, and the rest are pairs of two numbers. Each pair describes a borrower. The first number is the banks id and the second number is how much it borrowed. Assume that the maximum number of banks is 100. For example, the input for the five banks is as follows ( the limit is 201)
5 201
25 2 1 100.5 4 320.5
125 2 2 40 3 85
175 2 0 125 3 75
75 1 0 125
181 1 2 125
The total assets of bank 3 is 75 plus 125 which is under 201 so the bank is unsafe. After bank 3 is unsafe the total assets of bank 1 becomes 125 + 40 and is now also unsafe. The output should be "Unsafe banks are 3 1"
This is my current solution to the problem. I can't figure out how to get it to find all the unsafe banks. Just the first one. I have it set to take static input for testing. I have the working user input code ready to go if I can just get it to work properly.
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 100;
double balance[SIZE];
double loan[SIZE][SIZE];
int nobanks;
int limit;
int i = 0;
int j = 0;
int k = 0;
int noborrowers;
double assets[SIZE];
bool isSafe[SIZE];
bool newunsafefound = true;
cout << "Enter number of banks and the limit:" << endl;
// Set all of the data
nobanks = 5;
limit = 201;
balance[0] = 25.0;
balance[1] = 125.0;
balance[2] = 175.0;
balance[3] = 75.0;
balance[4] = 181.0;
loan[0][1] = 100.5;
loan[0][4] = 320.5;
loan[1][2] = 40.0;
loan[1][3] = 85.0;
loan[2][0] = 125.0;
loan[2][3] = 75.0;
loan[3][0] = 125.0;
loan[4][2] = 125.0;
// Set array to all true values
for(i = 0; i < nobanks; i++)
{
isSafe[i] = true ;
}
cout << "Unsafe banks are: ";
i=0;
while(isSafe[i] == true)
{
newunsafefound=false;
i=0;
do
{
assets[i] = balance[i]; //Set assets to balance
for (j = 0; j < nobanks; j++) // Check if a bank has loans and add them to assets
{
if (loan[i][j] >= 0)
assets[i] += loan[i][j];
}
if (assets[i] < limit) // Check to see if current bank meets limit
{
isSafe[i] = false; // Set bank to not safe if limit not met
newunsafefound = true;
cout << i << " " ; //Display the bank that is unsafe and a space for the next bank
k=0;
for (k = 0; k < nobanks; k++)
{
loan[i][k] = 0; //Set banks loans to 0 if unsafe.
k++;
}
}
i++;
} while(i < nobanks);
}
return (0);
}
What am I doing wrong?
You have to explicitly initialize the loan array, so the elements you aren't using don't have arbitrary values:
double loan[SIZE][SIZE] = {{0}};
Also loan[i][k] = 0; means that you are zeroing the loan the bank i has given to the bank k, but what you want is to zero any money that the bank i has borrowed to the bank k.
And there is a problem:
in the exit condition of your outer loop (it would only exit if the last bank (nobank-1) was unsafe),
in the handling of newunsafefound which doesn't do what the variable name suggests.
for (k = 0; k < nobanks; k++)
{
loan[i][k] = 0; //Set banks loans to 0 if unsafe.
k++;
}
That extra increment for k looks very suspicious ;)
// Astrid Giraldo
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
int n; // number of banks
double limit; // Minimum total assets for keeping a bank safe.
System.out.println("Enter number of banks: ");
n = input.nextInt();
System.out.println("Enter minimum total assets to be a safe bank: ");
limit = input.nextDouble();
double[][] borrowers = new double[n][n];
double[] balance = new double[n];
int numBorrowers;
for (int i = 0; i < borrowers.length; i++) {
System.out.println("Enter the bank's balance");
balance[i] = input.nextDouble();
System.out.println("Enter number of borrowers from this bank");
numBorrowers = input.nextInt();
for (int j = 0; j < numBorrowers; j++) {
System.out.println("Enter borrower bank id and the amount borrowed: ");
borrowers[i][input.nextInt()] = input.nextDouble();
}
}
markUnsafeBanks(borrowers,balance, limit);
displayUnsafeBanks(borrowers, balance, limit);
}
public static double analizeUnsafeBanks(double[][] borrowers, double[] balance, int bankId) {
double sum = balance[bankId];
for (int i = 0; i < borrowers.length; i++) {
sum += borrowers[bankId][i];
}
return sum;
}
public static void setLoanToZero(double[][] borrowers, double[] balance, int unsafeBankId, double limit) {
for (int i = 0; i < borrowers.length; i++) {
if (borrowers[i][unsafeBankId] > 0) {
borrowers[i][unsafeBankId] = 0;
if ( unsafeBankId > i && analizeUnsafeBanks(borrowers, balance, i) < limit) {
setLoanToZero(borrowers, balance, i, limit);
}
}
}
}
public static void markUnsafeBanks(double[][] borrowers, double[] balance, double limit) {
for (int i = 0; i < borrowers.length; i++) {
if (analizeUnsafeBanks(borrowers, balance, i) < limit) {
setLoanToZero(borrowers, balance, i, limit);
}
}
}
public static void displayUnsafeBanks(double[][] borrowers, double[] balance, double limit){
for (int i = 0; i < borrowers.length; i++) {
double assets = analizeUnsafeBanks(borrowers,balance,i);
if ( assets < limit) {
System.out.println("Bank " + i + " is unsafe. It assets are " + assets);
}
}
}