首页 > 代码库 > 记账类问题ACing
记账类问题ACing
1,用函数实现财务现金记账
#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,用函数实现餐厅记账
#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; }
记账类问题ACing
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。