| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1468 人关注过本帖
标题:求本金,试过了,调试了还是不行
只看楼主 加入收藏
游鹰
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2017-11-10
结帖率:0
收藏
已结贴  问题点数:10 回复次数:4 
求本金,试过了,调试了还是不行
题目内容:
设capital是最初的存款总额(即本金),rate是整存整取的存款年利率,n 是储蓄的年份,deposit是第n年年底账号里的存款总额。已知如下两种本利之和的计算方式:
按复利方式计息的本利之和计算公式为:deposit  =  capital * (1 + rate) n
按普通计息方式计算本利之和的公式为:deposit  =  capital  * (1 + rate * n)
已知银行整存整取不同期限存款的年息利率分别为:
存期1年,利率为 0.0225
存期2年,利率为 0.0243
存期3年,利率为 0.0270
存期5年,利率为 0.0288
存期8年,利率为 0.0300
若输入其他年份,则输出"Error year!"

编程从键盘输入存钱的本金和存款期限,然后再输入按何种方式计息,最后再计算并输出到期时能从银行得到的本利之和,要求结果保留到小数点后4位。
输入提示信息:"Input capital, year:"
输入提示信息:"Compound interest (Y/N)?"
存期输入错误的提示信息: "Error year!\n"
本金及存款期限的输入格式: "%lf,%d"
是否选择复利计算的输入格式: " %c" (注意:%c的前面有一个空格。输入的字符大小写皆可,即Y或y,N或n皆可)
输出格式:"rate = %.4f, deposit = %.4f\n"


#include <stdio.h>
#include <math.h>
int main()
{
    int year;
    float deposit,capital;
    float rate;
    char Y,y,N,n;
    printf("Input capital, year:");
    scanf("%lf,%d",&capital,&n);
    switch (n)
    {
        printf("Compound interest (Y/N)?");
        if(scanf(" %c",&y)||scanf(" %c",&y))
            {
                switch(n)
                {
                    case 1: rate=0.0225;
                          deposit  =  capital * pow((1 + rate),year);
                           printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                           break;
                    case 2: rate=0.0243;
                          deposit  =  capital * pow((1 + rate),year);
                          printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                          break;
                    case 3: rate=0.0270;
                             deposit  =  capital * pow((1 + rate),year);
                             printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                           break;
                    case 5: rate=0.0288;
                         deposit  =  capital * pow((1 + rate),year);
                          printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                          break;
                    case 8: rate=0.0300;
                         deposit  =  capital * pow((1 + rate),year);
                         printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                         break;
                    default:
                        printf("Error year!\n");
                }

            }

        if(scanf(" %c",&N)||scanf(" %c",&n))
            {
                switch(n)
                {
                    case 1:rate=0.0225;
                         deposit  =  capital  * (1 + rate * year);
                         printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                         break;
                    case 2: rate=0.0243;
                         deposit  =  capital  * (1 + rate * year);
                         printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                         break;
                    case 3: rate=0.0270;
                          deposit  =  capital  * (1 + rate * year);
                          printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                         break;
                    case 5: rate=0.0288;
                         deposit  =  capital  * (1 + rate * year);
                           printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                          break;

                    case 8: rate=0.0300;
                        deposit  =  capital  * (1 + rate * year);
                        printf("rate = %.4f, deposit = %.4f\n",rate,deposit);
                        break;
                    default:
                        printf("Error year!\n");

                }
            }

    }


}
搜索更多相关主题的帖子: 输入 year printf case break 
2017-12-23 12:03
游鹰
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2017-11-10
收藏
得分:0 
编译链接没错误,运行就不行
2017-12-23 12:10
虫眼
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:10
帖 子:314
专家分:1121
注 册:2017-11-29
收藏
得分:10 
怎么个不行法?
2017-12-23 12:21
虫眼
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:10
帖 子:314
专家分:1121
注 册:2017-11-29
收藏
得分:0 
这都什么啊,%lf应该对应double,%d对应int
程序代码:
float deposit,capital;
    float rate;
    char Y,y,N,n;
    printf("Input capital, year:");
    scanf("%lf,%d",&capital,&n);
2017-12-23 12:40
虫眼
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:10
帖 子:314
专家分:1121
注 册:2017-11-29
收藏
得分:0 
然后你还要
switch(n)
                {
                    case 1:

2017-12-23 13:01
快速回复:求本金,试过了,调试了还是不行
数据加载中...
 
   



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

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