here is the picture of result of this program /我的问题是关于如何使跑步总数保持循环? 因为在我的程序中,总债务将仅基于循环终止之前用户的最后输入,而不是从所有债权人那里获得总债务
/This program is for calculating the total debt
#include <stdio.h>
#include <string.h>
int main()
{
float cb,ir,si,totaldebt; //local declaration
int time,i,sum=0;
char c[25];
printf("------------Welcome to Debt Management System-------------");
printf("\nNOTE:\nDear users,\n\tYou have to enter the creditor's name if you have a debt. But if you have nothing debt left, just enter none");
for (i=1;i>=1;i++)
{
printf("\n%d)Name of the creditor: ",i);
//the user inputs the name of the creditor
scanf("%s", c);
if (strcmp(c, "none") == 0) // condition wherein if the user inputs "none" in the name of the creditor, the loop will terminate
{
break;
}
printf("Enter your current balance: ");//the user inputs current balance from the said creditor
scanf("%f",&cb);
printf("Enter its interest rate: "); //the user inputs the interest rate of of the debt
scanf("%f",&ir);
printf("Enter time for the loan: ");//the user inputs month
scanf("%d",&time);
si=cb*ir*time/100;//simple interest
totaldebt=si+cb; //simple interest + current balance
sum+=totaldebt;
}
printf("The total balance you have for now is: %.2f\n",totaldebt); //
if (totaldebt<=5000)
{
printf("\nCongratulations!\n You only have %.2f debt left\n",totaldebt);
}
else
{
printf("\nWork harder because out of DEBT is out of DANGER\n");
}
return 0;
}
答案 0 :(得分:0)
您已经在if(true)
中跟踪运行总计。您只需要使用它:
sum