Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting an error in my program where it keeps scanning. It happens whenever

ID: 3928601 • Letter: I

Question

I am getting an error in my program where it keeps scanning. It happens whenever I modify my power function. I tried every compination of parenthisis and breaking the function into other functions, included <math.h> and still have no luck can someone tell me what I am doing wrong here?

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
  
//A = P(1 + rt); R = r * 100
// P = Principal Amount or amount barrowed
//I = Interest Amount
//r = Rate of Interest per year in decimal; r = R/100
//t = Time Period involved in months or years
//A = Total Accrued Amount (principal + interest)


double userMoney = 0;
double moneyOwed = 0;
double interestRate =0;
double monthlyLoanPayment = 0;
double currentAge = 0;
double retireAge = 0;
double totalTime = 0;
double totalMoneyOwed = 0;
double investmentReturnRate = 0;
double futureInvestment = 0;
double moneyAfterMinPayment = 0;
double investmentFunction = 0;
printf("Enter how much money you will be putting towards loans/retirement each month: ");
scanf("%lf ",&userMoney);
printf("Enter how much you owe in loans: ");
scanf("%lf ",&moneyOwed);
printf("Enter the annual interest rate of the loans: ");
scanf("%lf ", &interestRate);
printf("Enter your minimum monthly loan payment: ");
scanf("%lf ",&monthlyLoanPayment);
printf("Enter your current age: ");
scanf("%lf ",&currentAge);
printf("Enter the age you plan to retire at: ");
scanf("%lf ",&retireAge);
printf("Enter the annual rate of return you predict for your investments:");
scanf("%lf",&investmentReturnRate);
double monthlytotalTime = (retireAge-currentAge)*12;
double totalTimeYears = retireAge-currentAge;
double count = 0; // n is number of years
double Savingmoney = 0;
for (count=1; moneyOwed>=userMoney ;count++ ){

//double totalMoneyOwed1 =((moneyOwed*interestRate/12)+moneyOwed);
moneyOwed = moneyOwed*pow(((interestRate/12) +1),count);

moneyOwed = moneyOwed-userMoney;

//printf(" Total money owed is %lf ",moneyOwed);

}
printf("%lf ",count);

Explanation / Answer

for (count=1; moneyOwed>=userMoney ;count++ )
{
double res = (interestRate/12) +1; //do this change
double totalMoneyOwed1 =((moneyOwed*interestRate/12)+moneyOwed);
moneyOwed = moneyOwed*pow(res,count);
moneyOwed = moneyOwed-userMoney;
printf(" Total money owed is %lf ",moneyOwed);
}
printf("%lf ",count);