C程序显示多张照片

问题描述 投票:0回答:2

我写了一个C代码来计算电费它给了我期望的输出,但是它重复了太多的输出,我尝试调试它,但是似乎不知道我在哪里弄错了,有人可以查看我的代码吗?我只希望第一个输出可见,但不是所有这些结果都可以看到

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

int main(){
    GetInputs();
    CalConsumCharge();
    CalExtraCharges();
    DispBill();
}

void GetInputs(){
    int unittot;
    int unit1;
    int Prev_Cons;
    printf("Enter Previous units consumption: ");
    scanf("%d",&Prev_Cons);
    printf("Enter the units consumed: ");
    scanf("%d",&unittot);
    unit1 = unittot - Prev_Cons;
    CalConsumCharge(unit1);
}

void CalConsumCharge(int unit){
    int total = 0;
    if(unit<=50){
        total = (unit*22);
    }
    else if(unit<=100){
        total = ((50*22)+(unit-50)*30);
    }
    else if(unit<=200){
        total = ((50*22)+(50*30)+(unit-100)*36);
    }
    else if(unit<=350){
        total = ((50*22)+(50*30)+(100*36)+(unit-200)*70);
    }
    else if(unit<=650){
        total = ((50*22)+(50*30)+(100*36)+(150*70)+(unit-350)*90);
    }
    else if(unit<=1000){
        total = ((50*22)+(50*30)+(100*36)+(150*70)+(300*90)+((unit-650)*135));
    }
    else{
        total = ((unit*145));
    }

    CalExtraCharges(total);
}

void CalExtraCharges(int total){
    int total1;
    total = total/100;
    if(total>=2000){
        total1 = total + 10 +20;
    }
    else{
        total1 = total +10;
    }
    DispBill(total1);
}

void DispBill(int total1){
    if(total1>=2000){
        printf("A penalty Charge was Placed Because your bill is over 2000 L.E");
        printf("Bill amount is: %d L.E",total1);
    }
    else if(total1<2000) {
        printf("your bill is : %d L.E",total1);
    }
}

enter image description here

c variables debugging output
2个回答
0
投票

确定,此代码需要大量的关注和关注。我很惊讶您可以编译并运行它。您的主要功能只需要调用GetInputs(),因为它会调用所有其他功能。


0
投票

您应该编译代码,然后查看会发生什么(错误,警告)。

© www.soinside.com 2019 - 2024. All rights reserved.