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

其实题目很简单,就是要求写一个能计算你的存款能用多少年多少月的程序。
要程序问你一共有多少存款,你每个月需提款多少,你每年的存款利息是多少,最后算出你所有的存款能用多少年多少月。

我可以写到让程序算出你第一月提款后还剩下多少钱,,,但不知道怎么让他一直计算到我所需的提款少于我的存款,然后计算出我的存款能用多少年多少月。。。我不懂我的while哪里用的不对了。。。。55555555555555555555

请帮忙指点一下吧。。。谢谢

leftover=剩余存款
withdraw=每月提款
nominalrate=年利息
principle=全部存款
interest=每月所得利息

#include <stdio.h>
#include <math.h>

int main(void)
{
float nominalrate, principle, withdraw, interest, leftover;
int months=0, years=0;

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

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

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

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

nominalrate *= 0.01; /*把百分比换算成小数点*/

interest = (principle-withdraw)*nominalrate/12; /*每月所得利息计算*/

leftover = principle-withdraw+interest; /*每月月底的剩余存款计算*/


while(leftover >= withdraw){


if(++months>12) {
months=1;
years ++;
}
}


if(leftover < withdraw){

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

return 0;
}

加粗部分是我不知道怎么写的部分。。。。。

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

搜索更多相关主题的帖子: 存款 列表 提款 leftover 
2007-09-09 13:48
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 

#include <stdio.h>
#include <math.h>

int main(void)
{
float nominalrate, principle, withdraw, interest, leftover;
int months=0, years=0;

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

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

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

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

nominalrate *= 0.01; /*把百分比换算成小数点*/


for(leftover=principle;leftover>=withdraw;months++)
{
interest = (leftover-withdraw)*nominalrate/12; /*每月所得利息计算*/

leftover = leftover-withdraw+interest; /*每月月底的剩余存款计算*/
}
years=months/12;
months=months%12;

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


return 0;
}

就这样。你的黑体部分真的是一团糟。。。。呵呵,这么说不要见怪


我不是学经济的,我是这样认为你的每月利息:当月利息等于当月剩余存款乘以月利率。如果不是这样算,请说明
另外,只要认为剩余存款不足以支付下个月的提款,即中止循环,输出能足支付的时间。

[此贴子已经被作者于2007-9-9 15:13:43编辑过]


代替leisure1980广告下: 群号45146331
2007-09-09 15:03
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
谢谢jinxin3256,,好人啊。。

我刚才试了一下,试的时候发现有的数组输入后工作,有的数组却不工作。。

还有
years=months/12;
months=years%12;
这两行是什么意思呢?

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


2007-09-09 15:18
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
啊。。好像正常工作了~~~。。。。

2007-09-09 15:25
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
太感谢了~~~~。。我现在试试把计算结果已表格式样显示出来。

2007-09-09 15:29
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 
呵呵,我也是菜鸟。刚学这个,不到10天,以后可以多交流
QQ 85505162

代替leisure1980广告下: 群号45146331
2007-09-09 15:38
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 
years=months/12;
months=months%12;

第一行为求商,取整;
第二行为求模(就是求余数)

[此贴子已经被作者于2007-9-9 15:43:11编辑过]


代替leisure1980广告下: 群号45146331
2007-09-09 15:40
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
以下是引用jinxin3256在2007-9-9 15:40:09的发言:
years=months/12;
months=months%12;

第一行为求商,取整;
第二行为求模(就是求余数)



嗯嗯。。难怪了。。你第一次帖的是years=months%12..所以没工作。。。。现在好了~~~~~谢谢~~~o(∩_∩)o


2007-09-09 15:46
jinxin3256
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-9-7
收藏
得分:0 
嗯,开始写错了,改回来了

代替leisure1980广告下: 群号45146331
2007-09-09 15:49
豌豆2
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-9-9
收藏
得分:0 
惭愧啊。。同样都是刚学的。。。。。。。。。。

2007-09-09 15:50
快速回复:[求助]还是同一道存款计算程序,有一些关于列表的问题在11楼。
数据加载中...
 
   



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

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