Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何保持总流量_C_Loops_For Loop - Fatal编程技术网

C 如何保持总流量

C 如何保持总流量,c,loops,for-loop,C,Loops,For Loop,/我的问题是如何保持循环中的运行总量? 因为在我的程序中,总债务将只基于循环终止之前用户的最后一次输入,而不是从所有债权人那里获得总债务 /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

/我的问题是如何保持循环中的运行总量? 因为在我的程序中,总债务将只基于循环终止之前用户的最后一次输入,而不是从所有债权人那里获得总债务

/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;
}
/此程序用于计算总债务
#包括
#包括
int main()
{
浮动cb、ir、si、totaldebt;//本地声明
整数时间,i,和=0;
charc[25];
printf(“--------------欢迎使用债务管理系统----------------”);
printf(“\n注意:\n默认用户,\n\t如果您有债务,您必须输入债权人的名称。但是如果您没有剩余债务,只需输入none即可”);
对于(i=1;i>=1;i++)
{
printf(“\n%d)债权人名称:”,i);
//用户输入债权人的名称
scanf(“%s”,c);
if(strcmp(c,“none”)==0)//如果用户在债权人的名称中输入“none”,循环将终止
{
打破
}
printf(“输入当前余额:”;//用户输入上述债权人的当前余额
scanf(“%f”、&cb);
printf(“输入利率:”;//用户输入债务的利率
扫描频率(“%f”和“ir”);
printf(“输入贷款时间:”;//用户输入月份
扫描频率(“%d”和时间);
si=cb*ir*time/100;//单利
totaldebt=si+cb;//单利+当前余额
总和+=总债务;
}
printf(“您目前的总余额为:%.2f\n”,totaldebt)//

如果(totaldebt您已经在
sum
中记录了运行的总计。您只需使用它:

float sum = 0;
...

printf("The total balance you have for now is: %.2f\n",sum ); //
if (sum <=5000)
{
    printf("\nCongratulations!\n You only have %.2f debt left\n",sum );
}
else
{
    printf("\nWork harder because out of DEBT is out of DANGER\n");
}
浮点和=0;
...
printf(“您目前的总余额为:%.2f\n”,总和)//

如果(sum)要具体说明你想问什么。
for(i=1;i>=1;i++)
看起来像一个可怕的循环。即使你打破了循环,你也应该做一些类似
的事情,而(1)
for(;;)
则。
i
可能会在其他方面溢出。谢谢,这是一个巨大的帮助