| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1366 人关注过本帖
标题:[求助]还是同一道存款计算程序,有一些关于列表的问题在11楼。
只看楼主 加入收藏
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 

问题又来了,还是同样一道题,我希望把结果用列表一年一年显示出来。

比如:

年 存款 利息
1 1000 (当年利息总结)
2 500 (当年利息总结)
3 0 (当年利息总结)


我写的这个程序只能把最后一年的存款余额和最后一共得到的利息显示出来了。
如果让它一年年都显示出来呢?
(程序在附件里)




uGArkOXp.txt (2.2 KB)

[此贴子已经被作者于2007-9-9 21:03:59编辑过]


2007-09-09 21:01
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:0 
年 存款 利息

这个嘛```你可以在计算MONEY之前printf出来``
然后在计算的时候```

你是 年 存款 利息``计算一个输出一个吧```

在输出年下的数字时后面多点空个``存款一样``利息输完一个\N````

这是输出格式问题```LZ可以在printf语句里修改```



女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2007-09-09 21:07
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 

#include <stdio.h>
#include <math.h>
#include <dos.h>
int main(void)
{
float nominalrate, principle, withdraw, interest, leftover, balance, interests;
int months=0, years=0, table;

printf("This program is a retirement calculator, it calculates how long your savings will last.\n");

printf("\nPlease enter your total savings in dollar: \n");
scanf("%f",&principle);

while (principle <= 0)
{
printf("\nSorry, you have entered an invalid value. ");
printf("\nPlease enter another number that's greater then 0: \n");
scanf("%f", &principle);
}

printf("\nPlease enter the amount of money withdrawn from savings each month: \n");
scanf("%f",&withdraw);

while (withdraw <= 0)
{
printf("\nSorry, you have entered an invalid value. ");
printf("\nPlease enter another number that's greater then 0: \n");
scanf("%f", &withdraw);
}

printf("\nPlease enter your yearly interest rate: ");
scanf("%f",&nominalrate);

while (nominalrate > 100 || nominalrate <= 0)
{
printf("\nThe number you have entered is invalid.\n ");
printf("\nPlease enter a percentage between 0 and 100, without the percentage symbol: \n");
scanf("%f", &nominalrate);
}

if(principle<withdraw)
printf("\nyou principle have run out!!");

nominalrate *= 0.01; /*This converts percentage to decimal*/


if(principle*nominalrate/12>withdraw)
{printf("\nyou principle never run out!!");
system("pause");}


for(leftover=principle;leftover>=withdraw;months++){

interest = (leftover-withdraw)*nominalrate/12; /*Calculate monthly interest to be credited*/

leftover = leftover-withdraw+interest; /*Calculate the total amount left at the end of the month*/
}
years=months/12;
months=months%12;

printf("\nYour current savings will last %d years and %d months.\n", years,months);

printf("\n\nWould you like to view the details in a table? Yes=1/ No=0: ");
scanf("%d", &table);

if (table == 1)
{float t=0,interest=0;
int months=0,years=0;
printf("\n\n%6s%18s%18s\n", "Year","Balance($)","Interests($)");
printf("-------------------------------------------------\n");
for(leftover=principle;leftover>=withdraw;)
{
months++;

interest = (leftover-withdraw)*nominalrate/12; /*Calculate monthly interest to be credited*/
leftover = leftover-withdraw+interest;

if(months%12!=0)
{
t=t+interest;
}
else if(months%12==0)
{
t=t+interest;
years++;
printf("\n\n%6d%18f%18f\n", years,leftover,t);
t=0;
}

}
if(leftover<withdraw)
{years++;
printf("\n\n%6d%18f%18f\n", years,leftover,t);
}
}

return 0;
}

弄了好久,总算是弄出来了。。。调试通过了。


刚才又修改了下:这个是完全不计入余款利息的,只要发现余额不足下个月取就结束,你可以和下下楼的那个程序对照下,看你要的是哪个

[此贴子已经被作者于2007-9-10 19:39:49编辑过]


代替leisure1980广告下: 群号45146331
2007-09-10 09:04
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
非常感谢~。。我电脑中毒了。。。重装系统。。还没办法开Q。。。。现谢谢你的帮忙了~

2007-09-10 19:13
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 

#include <stdio.h>
#include <math.h>
#include <dos.h>
int main(void)
{
float nominalrate, principle, withdraw, interest, leftover, balance, interests;
int months=0, years=0, table;

printf("This program is a retirement calculator, it calculates how long your savings will last.\n");

printf("\nPlease enter your total savings in dollar: \n");
scanf("%f",&principle);

while (principle <= 0)
{
printf("\nSorry, you have entered an invalid value. ");
printf("\nPlease enter another number that's greater then 0: \n");
scanf("%f", &principle);
}

printf("\nPlease enter the amount of money withdrawn from savings each month: \n");
scanf("%f",&withdraw);

while (withdraw <= 0)
{
printf("\nSorry, you have entered an invalid value. ");
printf("\nPlease enter another number that's greater then 0: \n");
scanf("%f", &withdraw);
}

printf("\nPlease enter your yearly interest rate: ");
scanf("%f",&nominalrate);

while (nominalrate > 100 || nominalrate <= 0)
{
printf("\nThe number you have entered is invalid.\n ");
printf("\nPlease enter a percentage between 0 and 100, without the percentage symbol: \n");
scanf("%f", &nominalrate);
}

if(principle<withdraw)
printf("\nyou principle have run out!!");

nominalrate *= 0.01; /*This converts percentage to decimal*/


if(principle*nominalrate/12>withdraw)
{printf("\nyou principle never run out!!");
system("pause");}


for(leftover=principle;leftover>=withdraw;months++){

interest = (leftover-withdraw)*nominalrate/12; /*Calculate monthly interest to be credited*/

leftover = leftover-withdraw+interest; /*Calculate the total amount left at the end of the month*/
}
years=months/12;
months=months%12;

printf("\nYour current savings will last %d years and %d months.\n", years,months);

printf("\n\nWould you like to view the details in a table? Yes=1/ No=0: ");
scanf("%d", &table);

if (table == 1)
{float t=0,interest=0;
int months=0,years=0;
printf("\n\n%6s%18s%18s\n", "Year","Balance($)","Interests($)");
printf("-------------------------------------------------\n");
for(leftover=principle;leftover>=withdraw;)
{
months++;

interest = (leftover-withdraw)*nominalrate/12; /*Calculate monthly interest to be credited*/
leftover = leftover-withdraw+interest;

if(months%12!=0)
{
t=t+interest;
}
else if(months%12==0)
{
t=t+interest;
years++;
printf("\n\n%6d%18f%18f\n", years,leftover,t);
t=0;
}

}
if(leftover<withdraw)
{years++;
t=t+interest+leftover*nominalrate/12;
leftover=leftover+leftover*nominalrate/12;
printf("\n\n%6d%18f%18f\n", years,leftover,t);
}
}

return 0;
}

这个是计入了最后余款利息的。。。因为我不知道具体是要算哪一个,最后一个月指的是取完钱后发现下个月不够取,还是发现已经取不出的那个月?


代替leisure1980广告下: 群号45146331
2007-09-10 19:34
acrobat
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-9-8
收藏
得分:0 
这些问题都是我们新手常犯的问题呀!我们以后得注意了呀!

一起加油呀!

数学的存在告诉我们了一个成语,那就是“世事无绝对”,每件事都会同时存N种的可能...
2007-09-11 17:45
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 
楼上所说的问题是?

代替leisure1980广告下: 群号45146331
2007-09-11 19:42
快速回复:[求助]还是同一道存款计算程序,有一些关于列表的问题在11楼。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042283 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved