前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >记账类问题汇总

记账类问题汇总

作者头像
Zoctopus
发布2018-06-04 11:21:31
7510
发布2018-06-04 11:21:31
举报

(注:暂时先记录这些问题,后期会持续更新)

1,用函数实现财务现金记账

代码语言:javascript
复制
#include<stdio.h>
float cash;  //定义全局变量,保存现金余额
int main(void)
{
    int choice;
    float value;
    void income(float number),expend(float number);  //函数声明
    
    cash = 0;
    printf("Enter operte choice(0--end,1--income,2--expend):");
    scanf("%d",&choice);  //输入操作类型
    while(choice != 0){
        if(choice == 1||choice == 2){
            printf("Enter cash value:");  //输入操作现金额 
            scanf("%f",&value);
            if(choice == 1)
                income(value);  //计算现金收入 
            else
                expend(value);  //计算现金输出
            printf("current cash:%.2f\n",cash); 
        }
        printf("Enter operte choice(0--end,1--income,2--expend):");
        scanf("%d",&choice);  //继续输入操作类型
    } 
    return 0;
} 

void income(float number)
{
    cash = cash + number;  //改变全局变量cash 
}

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

2,用函数实现餐厅记账

代码语言:javascript
复制
#include<stdio.h>
float total = 0.0;
short count = 0;
short tax_percent = 6;
float add_with_tax(float f)  //返回一小笔金额
{
    float tax_rate = 1 + tax_percent / 100.0;  //有了.0,计算就会以浮点数进行,否则表达式会返回整数
    total = total + (f * tax_rate);
    count = count + 1;
    return total; 
} 

int main()
{
    float val;
    printf("Price of item:");
    while(scanf("%f",&val)==1){
        printf("Total so far:%.2f\n",add_with_tax(val));
        printf("Price of item:");
    }
    printf("\nFinal total:%.2f\n",total);
    printf("Number of items:%hi\n",count);
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-04-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1,用函数实现财务现金记账
  • 2,用函数实现餐厅记账
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档