• 0311 复利计算


    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    
    double p ; //现值
    double f ; //终值
    double i ; //利率
    int n;  //周数
    int m;
    
    window(){
    printf("   ===----------------------===
    
    ");
    printf("
    
    	单复利查询系统
    
    
    
    ");
    printf("   ===----------------------===
    
    
    
    
    ");
    system("pause");
    }
    
    int menu(){
    char c;
    do{
    system("cls");
    printf("=============================
    ");
    printf("	|1.单利查询   	|
    ");
    printf("	|2.复利查询   	|
    ");
    printf("	|0.退出程序   	|
    ");
    printf("	|请你选择(0~2): |
    ");
    c=getchar();
    }while(c<'0'||c>'2');
    return (c-'0');
    
    }
    
    void danlia(){
        printf("请输入现值:");
        scanf("%lf",&p);
        printf("请输入利率:");
        scanf("%lf",&i);
        printf("请输入周数:");
        scanf("%d",&n);
        f=p*i*n+p;
        printf("终值为%lf",f);
    }
    
    void danlib(){
        printf("请输入终值:");
        scanf("%lf",&f);
        printf("请输入利率:");
        scanf("%lf",&i);
        printf("请输入周数:");
        scanf("%d",&n);
        p=f/(1+i*n);
        printf("现值为%lf",p);
    }
    
    void fulia()
    {
        printf("请输入现值:");
        scanf("%lf",&p);
        printf("请输入利率:");
        scanf("%lf",&i);
        printf("请输入周数:");
        scanf("%d",&n);
        f=p*pow(1+i,n);
        printf("终值为%lf",f);
    }
    
    void fulib()
    {
        printf("请输入终值:");
        scanf("%lf",&f);
        printf("请输入利率:");
        scanf("%lf",&i);
        printf("请输入周数:");
        scanf("%d",&n);
        p=f/pow(1+i,n);
        printf("现值为%lf",p);
    }
    
    
    
    int main(){
        
        window();
        switch(menu()){
        case 1:
        system("cls");
        printf("单利");
        printf("	|-------------------|
    ");
        printf("	|1.现值查终值	    |
    ");
        printf("	|2.终值查现值	    |
    ");
        printf("	|-------------------|
    ");
        printf("请选择计算方式:
    ");
    
        scanf("%d",&m);
        if(m!=1 && m!=2)  
        {  
                printf("输入错误!
    ");  
                break; 
        }    
        if(m==1){
            system("cls");
            danlia();
            break;
        
        }    
         if(m==2){
            system("cls");
            danlib();
            break;
        }
        
        case 2:
        system("cls");
        printf("复利");
        printf("请选择计算方式:
    ");
        printf("	|-------------------|
    ");
        printf("	|1.现值查终值	    |
    ");
        printf("	|2.终值查现值	    |
    ");
        printf("	|-------------------|
    ");
        printf("请选择计算方式:
    ");
        scanf("%d",&m);
        
        if(m!=1 && m!=2)  
        {  
            printf("输入错误!请重新输入!
    ");  
            scanf("%d",&m);  
        }   
        else if(m==1){
            system("cls");
            
            fulia();
            break;
             
        }
        else if(m==2){
            system("cls");
            
            fulib();
            break;
            
        }
    
        case 0:
        printf("
    		see you!
    ");
        printf("
    		");
        system("pause");
        exit(0);
        
        
        
        }
    
    
    }

    结果:


    主界面:

    选择界面:

    计算界面:

    计算方式:单利、复利

    主要功能:计算终值、计算投资值(已经实现功能)

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    数据库作业15:关系数据理论
    IPv6 — 实践
    Provisional headers are shown 说明走了缓存没有发送请求
  • 原文地址:https://www.cnblogs.com/cjh123/p/5272001.html
Copyright © 2020-2023  润新知