C语言-用函数实现财务现金记账

2020-01-08  本文已影响0人  广陵周惊蛰

问题描述:用函数实现财务现金记账

源代码:

/*用函数实现财务现金记账*/
#include<stdio.h>

float cash;
void income(float number),expend(float number);

int main(void)
{
    int choice;
    float value;
    
    cash=0;
    printf("Enter operate choice(o--end,1--income,--expand):");
    scanf("%d",&choice);
    while(choice!=0){
        if(choice==1||choice==2){
            scanf("%f",&value);
            if(choice==1)
                income(value);
            else
                expend(value);
            printf("current cash:%.2f\n",cash);
        }
        printf("Enter operate choice(o--end,1--income,--expand):");
        scanf("%d",&choice);
    }
    return 0;   
}

void income(float number)
{
    cash=cash+number;
}
void expend(float number)
{
    cash=cash-number;
}

运行结果:

财务现金记账

程序心得:

全局变量在相对较大的项目中使用,常常会造成不同函数的相互干扰,所以在变量使用中,应尽量使用局部变量。

程序参数:

上一篇 下一篇

猜你喜欢

热点阅读