初学C的一些迷茫
以下是一个简单个人理财程序,程序的问题出现在void income()和void disburse(),当输入一个具体的数字后sum函数并没有执行,程序可以运行,余额一直为0。。。。。。#include <stdio.h>
float sum;
void calculator()
{
int op1, op2, res;
char open;
scanf("%d", &op1);
open=getchar();
res=op1;
while(open!='=')
{
scanf("%d",&op2);
if(open=='s')
res=res+op2;
if(open=='d')
res=res-op2;
if(open=='*')
res=res*op2;
if(open=='/')
res=res/op2;
open=getchar();
}
printf("%d\n", res);
}
void inquire()
{
printf("当前余额为:%d元:\n",sum);
}
void income()
{
float x;
sum=0;
printf("请输入进账数额:\n");
scanf("%f",&x);
sum=sum+x;
}
void disburse()
{float x;
printf("请输入支出数额:\n");
scanf("%f",&x);
sum=sum-x;
}
void account()
{
int x;
printf("***********************************\n");
printf("1.支出 2.进账 3.退出 4.查询余额\n");
printf("***********************************\n");
scanf("%d",&x);
switch(x)
{
case 1: disburse();break;
case 2: income();break;
case 3: printf("欢迎使用,再见!\n");break;
case 4: inquire();break;
}
}
void password()
{
long int a;
int b=1;
do
{
printf("请输入密码!\n");
scanf("%d",&a);
if(a==123456)
{
printf("密码输入正确,欢迎进入个人理财系统!\n\n\n\n\n");
b=0;
}
else
printf("密码输入错误!\n");
}
while(b);
}
void main()
{
password();
loop: int x;
printf("\n******************************\n");
printf("\n个人理财系统1.0 by xiaochenxi\n");
printf("\n******************************\n");
printf("请选择管理项目:\n");
printf("1.详细账目输入\n");
printf("2.查询当前余额\n");
printf("3.小工具(计算器)\n");
printf("4.退出\n");
scanf("%d",&x);
switch(x)
{
case 1: account();goto loop;
case 2: inquire();goto loop;
case 3: calculator();goto loop;
case 4: printf ("欢迎再次使用,再见!"); break;
default:printf ("输入错误!"); break;
}
}