[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.9663115 [View]
File: 46 KB, 936x423, ScreenHunter_2793 Apr. 10 16.24.jpg [View same] [iqdb] [saucenao] [google]
9663115

>>9663017

nevermind:

[code]

#include <stdio.h>
int main (void) {


int countdays = 7;
double deposit = 0.01;
int totaldays= 0;
double balance = 0.01;
double inputMoney;

printf("Please enter the amount of money you want to accumulate:");
scanf("%lf", &inputMoney);

printf("\n");
printf("DAY\t\tDEPOSIT\t\tBALANCE\n");
printf("---\t\t-------\t\t-------\n");

while(balance <= inputMoney)
{

printf("%3d %9.2lf %10.2lf\n", countdays, deposit, balance);
countdays = countdays + 7;
totaldays++;
deposit = deposit + (deposit * 2);
balance += deposit;


}
printf("\n");
printf("It took %d weeks to accumulate at least $%.2lf\n", totaldays, inputMoney);

return 0;
}

[code/]

I ripped the code off from someone else and tailored the logic to work better.

I'm sure there is a more elegant way to do this with a for loop in c, but I don't know c so..

I hope I interpreted the question correctly.

Navigation
View posts[+24][+48][+96]