| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 502 人关注过本帖
标题:贷款计算器的设计题。。实在不会了。求帮忙
只看楼主 加入收藏
dongguo666
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
贷款计算器的设计题。。实在不会了。求帮忙
    设计一个贷款计算器,已知某银行当年的贷款利率如下:
    种类        年利率(%)
    <1年(包含1年)        7.47
    1-3年(包含3年)        7.56
    3-5年(包含5年)        7.74
    5年以上        7.83
要求用户输入贷款数额(万元)和年限后,根据公式
                                 还款总期数
             月利率×(1+月利率)
每月还款额=—————————————————————×贷款本金
                                 还款总期数
             月利率×(1+月利率)           -1
计算出每月还款额。
说明:
月利率=年利率/12
还款总期数=贷款年限×12
计算xy的值:
    double pow(double x,double y)   /*在头文件math.h中*/
   
具体过程:
提示用户输入姓名并接受用户输入;
提示用户输入贷款数额(单位为万元)并接受用户输入;
提示用户输入贷款年限并接受用户输入;
输出“姓名: xxx,贷款年限为xx年,贷款数额为xx万元,正确?(Y/N)”,如果用户输入Y,转到第5步,否则返回第1步。
输出下面的表格
    姓名:        贷款年限(年):
    贷款数额(元):        每月还款额(元):
    利息合计(元):        还款总额(元)
输出“是否进行新的计算(Y/N)?”,如果用户选择N,退出应用程序,否则返回到第1步。



#include <stdio.h>
#include <math.h>
int y;
double b,e,d;
float a;
char c[80],w,r;
void shut()
{
    printf("输入用户姓名\n");
    scanf("%s",c);
    printf("输入贷款数额\n");
    scanf("%f",&a);
    printf("输入贷款年限\n");
    scanf("%d",&y);
    printf("姓名:%s,贷款年限为%d年,贷款数额为%f万元,正确?(Y/N)\n",c,y,a);
    scanf("%d",&w);
}
void Switch()
{
    double x,k,l;
    switch(y)
    {
        case 0:
        case 1: x=0.0747; break;
        case 2:
        case 3: x=0.0756; break;
        case 4:
        case 5: x=0.0774; break;
        default: x=0.0783;
    }
    k=x/12*pow((1+x/12),(y*12));
    l=pow((1+x/12),(y*12));
    b=k/l*a*10000;
    e=a*x*y*10000;
    d=b*y*12*10000;
    printf("姓名:%s      贷款年限(年):%d\n贷款数额(元):%f  每月还款数额(元):%f\n利息合计(元):%f  还款总额(元):%f\n",c,y,a,b,e,d);
}
void p()
{
    printf("是否进行新的计算(Y/N)?\n");
    scanf("%c",&r);
}
void main()
{
    shut();



}


主函数实在不会写了。如果能写下去就帮忙写,不能的话重写也可以,最好别用太深难度的语句。初学c。谢谢各位大神!!
搜索更多相关主题的帖子: 银行 月利率 年利率 贷款利率 贷款计算器 
2011-06-27 14:13
劣质数轴
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:89
专家分:163
注 册:2010-11-19
收藏
得分:20 
程序代码:
/*

 * main.c

 *

 *  Created on: 2011-6-8

 *      Author: icelights

 */

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

#define APR1        0.0747    /*<1年(含1年)年利率*/
#define APR2        0.0756    /*1-3年(含3年)年利率*/
#define APR3        0.0774    /*3-5年(含5年)年利率*/
#define APR4        0.0783    /*5年以上年利率*/
#define A_TO_M      1/12      /*月利率 = 年利率 / 12*/
#define RTP         12        /*Reimbursement total periods还款总期数 =年限*12*/
#define LENGTH      80

struct LoanInfo
{
                          /*姓名*/
    char                  name[LENGTH];
                          /*贷款总额*/
    double                LoanAmount;
                          /*贷款年限*/
    double                LoanYear;
                          /*月付*/
    double                MonthlyPayment;
                          /*总利息*/
    double                TotalInterest;
                          /*还款总额*/
    double                ReimbursementAmount;
                          /*年利率*/
    double                apr;

    struct LoanInfo *     next;
};

void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
              struct LoanInfo * prv);

int main(void)
{
    int temp;
    struct LoanInfo * head = NULL;
    struct LoanInfo * prev, * current;


        current = (struct LoanInfo *)malloc(sizeof(struct LoanInfo));

        if (NULL == head)
        {
            head = current;
        }
        else
        {
            prev->next = current;
        }/*End of if (NULL == head)*/

        puts("请输入姓名");
        gets(current->name);
        fflush(stdin);

        puts("请输入贷款数额(单位:万元)");
        scanf("%lf", ¤t->LoanAmount);
        fflush(stdin);

        puts("请输入贷款年限");
        scanf("%lf", ¤t->LoanYear);
        fflush(stdin);

        printf("姓名:%s,贷款年限:%lf, 贷款数额%lf",
                current->name, current->LoanYear, current->LoanAmount);

        prev = current;

        puts("请确认Y/N");


        temp = getchar();

        switch(toupper(temp))
        {
            case 'Y'   :   CalcShow(current, head, prev);
                           break;
            case 'N'   :   free(current);
                           main();
                           break;
            default    :   puts("输入错误");
                           free(current);
                              break;
           }




    return 0;
}


void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
              struct LoanInfo * prv)
{
    char lcv_temp;

    if (cur->LoanYear <= 1)
        cur->apr = APR1;
    else if (cur->LoanYear <= 3)
        cur->apr = APR2;
    else if (cur->LoanYear <= 5)
        cur->apr = APR3;
    else
        cur->apr = APR4;
    /*End of if (year <= 1)*/

    cur->LoanAmount = 10000 * cur->LoanAmount;
    cur->ReimbursementAmount = cur->LoanAmount * pow((1 + cur->apr), cur->LoanYear);
    cur->MonthlyPayment = cur->ReimbursementAmount / (cur->LoanYear * RTP);
    cur->TotalInterest = cur->ReimbursementAmount - cur->LoanAmount;

    printf("姓名:%s 贷款年限:%.0lf\n"
           "贷款数额:%.2lf 每月还款额:%.2lf\n"
           "利息合计:%.2lf 还款总额:%.2lf\n",
           cur->name, cur->LoanYear, cur->LoanAmount,
           cur->MonthlyPayment, cur->TotalInterest, cur->ReimbursementAmount);

    puts("是否继续计算Y/N");

    lcv_temp = getchar();
        switch(toupper(lcv_temp))
        {
            case 'Y'   :   free(cur);
                           main();
                           break;
            case 'N'   :   free(cur);
                           exit(0);
            default    :   puts("输入错误");
                           free(cur);
                           main();
                              break;
           }


    system("pause");


}
2011-06-29 23:45
快速回复:贷款计算器的设计题。。实在不会了。求帮忙
数据加载中...
 
   



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

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