簡體   English   中英

使用 switch 計算單利和復利的程序

[英]Program using switch to calculate Simple and compound interest

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    float p,r,t,si,ci,a,temp;
    int ch;
    clrscr();
    printf("Enter p,r,t");
    scanf("%f%f%f",&p,&r,&t);
    printf("\n 1 for SI");
    printf("\n 2 for CI");
    printf("\n Select any option");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:
            si=(p*r*t)/100;
            printf("The simple interest is %f",si);
            break;
        case 2:
            temp=(1+r/100);
            a=p*pow(temp,t);
            ci=a-p;
            printf("The compound interest is %f",ci);
            break;
    }
    getch();
}

這是我寫的代碼,沒有錯誤。 我可以正確輸入 p、r 和 t。 當我輸入 1 或 2(SI 和 CI 的選擇)時,輸出屏幕會自動關閉並且沒有顯示輸出。 我只能看到我寫的代碼。 請告訴我我的錯誤是什么。

首先,使用

int main()

最后返回 int 。

那你有沒有看一下你的 var 值? 使用浮動而不分離你可以輸入什么? “2.34.678.9”? 如何區分值? 更喜歡在 scanf 中使用 %f %f %f 。 之后重試:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM