void fun(){
int i, ch float price = 9.8, in_price, total = 0 while (1){
printf("\n1.算账模式\n2.算账\n3.退出\n")
scanf("%d", &i)
switch (i){
case 1://算账模式
{
do{
printf("应付款金额 %f 元.\n付款金额:", price)
scanf("%f", &in_price)
printf("实际付款金额%f,应找零金额 %f 元.\n", in_price, in_price - price)
total += price
scanf("%d", &ch)
} while (ch != -1)
break
}
case 2:{
printf("收款总额:%6.2f 元.\n", total) break
}
case 3:
exit(0)
}
}
}
void main()
{
fun()
}
有随手记、 矜云记账、excel、手机自带的记事本等,以随手记为例,个人记账的方法如下(以iphone6手机为例,需要下载随手记APP):
1、打开随手记APP,在主界面点击“记一笔”按钮。
2、在随后进入的编辑界面上方选择款项类型,并填写其它信息,并在账户处填写“其它”。
3、在界面下方点击“保存”按钮。
4、若要查看年度流水记录,则可以在主界面点击“流水”,切换到需要查看的年份即可。
#include <stdio.h>#include <stdlib.h>
typedef struct moneydata
{
double n
struct moneydata* next
}NUM
//main
int main()
{
NUM* initial()
NUM* build(NUM* money)
void input(NUM* income,NUM* payment)
void output(NUM* income,NUM* payment)
double incomeSum(NUM* income)
double paymentSum(NUM* income)
double toplimit
double SUM
char ch
NUM *income,*payment
printf("enter your payment toplimit\n")
scanf("%lf",&toplimit)
fflush(stdin)
printf("*************************************************\n\n")
income=initial()
payment=initial()
for()
{
printf("please choose what you want to do\n")
printf("1.input 2.analyse 3.quit\n")
scanf("%c",&ch)
fflush(stdin)
printf("*************************************************\n\n")
switch(ch)
{
case '1':
input(income,payment)
printf("*************************************************\n\n")
break
//数据分析,包括输出收入总和,支出总和,对收入支出比较,输出利润和提醒是否要存钱了
case '2':
printf("please choose what you want to do\n")
printf("1.output income's sum 2.output payment's sum 3.compare with toplimit\n")
scanf("%c",&ch)
fflush(stdin)
switch(ch)
{
case '1':
SUM=incomeSum(income)
printf("%f\n",SUM)
break
case '2':
SUM=paymentSum(payment)
printf("%f\n",SUM)
break
case '3':
double profit
SUM=incomeSum(income)
profit=SUM
printf("your income's sum is:")
printf("%f\n",SUM)
SUM=paymentSum(payment)
printf("your payment's sum is:")
printf("%f\n",SUM)
profit=profit - SUM
printf("your profit is:")
printf("%f\n",profit)
if(profit<=0)
{
printf("you shoule save money!!\n")
}
else
{
printf("you can spend your money as you like\n")
}
break
}
printf("*************************************************\n\n")
break
case '3':
system("pause")
exit(0)
}
}
return 0
}
//table initial
//链表初始化
NUM* initial()
{
NUM* money
money=(NUM*)malloc(sizeof(NUM))
money->n=0
money->next=money
return money
}
//build
//链表扩展
NUM* build(NUM* money)
{
NUM* temp
temp=(NUM*)malloc(sizeof(NUM))
temp->n=0
money->next=temp
temp->next=money
return temp
}
//input
//数据输入
void input(NUM* income,NUM* payment)
{
NUM* build(NUM* money)
printf("please choose what you want to enter:\n")
printf("1.income 2.payment\n")
char ch
NUM* temp1,*temp2
scanf("%c",&ch)
fflush(stdin)
temp1=income
temp2=payment
switch(ch)
{
case '1':
printf("please enter your income today:\n")
temp1=build(temp1)
scanf("%lf",&temp1->n)
fflush(stdin)
break
case '2':
printf("please enter your payment today:\n")
temp2=build(temp2)
scanf("%lf",&temp2->n)
fflush(stdin)
break
default :printf("enter ERROR!\n")
return
}
}
//output
//数据输出
void output(NUM* income,NUM* payment)
{
printf("please choose what you want to do\n")
printf("1.output all income 2.output all payment\n")
char ch
NUM *temp1,*temp2
scanf("%c",&ch)
temp1=income
temp2=payment
switch(ch)
{
case '1':
for(temp1!=incometemp1=temp1->next)
{
printf("%f",temp1->n)
}
break
case '2':
for(temp2!=paymenttemp2=temp2->next)
{
printf(" %f",temp2->n)
}
break
default :printf("output ERROR!\n")
}
printf("\n")
}
//income calculate
//收入计算(收入和支出在不同的链表中,同时处理要返回两个值,这不可能)
//可以用引用,但引用是C++里面有的,楼主要求是C,所以就不用引用了,而且引用一般出错率很高
double incomeSum(NUM* income)
{
double sum
NUM* temp
temp=income->next
sum=0
for(temp!=incometemp=temp->next)
{
sum=sum + temp->n
}
return sum
}
//payment calculate
//支出计算
double paymentSum(NUM* payment)
{
double sum
NUM* temp
temp=payment->next
sum=0
for(temp!=paymenttemp=temp->next)
{
sum=sum + temp->n
}
return sum
}
还有啥不明白的地方可以问我,写个程序不容易啊亲,满意请采纳,程序本身是不难写的,只是有点麻烦……
这个程序只能做到对数据的录入和输出,比较收入支出的大小,想要其它功能再说吧。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)