一、问题遇到的现象和发生背景
代码没有报错,但密码输入成功后没有继续运行,只是一直重复上一步
二、相关代码
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <iostream>
#define MAX_NAME 11
#define MAX_DETAIL 21
#define M 155
#define N 155
using namespace std;
void add_income();
void search_income();
void changeTotalIncomeMoneyTOSelect(int usageJudge);
void selectIncomeByUsage();
void incomePercent();
void printfSingleIncome(int i);
void add_payout();
void search_payout();
void changeTotalPaymentMoneyTOSelect(int usageJudge);
void selectPaymentByUsage();
void paymentPercent();
void printfSinglePayment(int p);
void menu();
void allPayoutMoneyCount();
void allIncomeMoneyCount();
void readData();
void quit();
int numberJudge();
int usageJudge();
struct payment {
int id;
float money;
int year;
int month;
int day;
int usage;
float percent;
}payment[M];
struct comement {
int id;
float money;
int year;//年
int month;
int day;
int usage;
float percent;
}comement[N];
const char fileName[] = "d:\\test.txt";//文件存储路径
int currentMaxId;//当前文件中的最大id
int n;///当前文件中记录的数目
int m;
//收入数据
float totalIncomeMoney = 0;
float istudyMoney = 0;
float icateringMoney = 0;
float iclothesMoney = 0;
float irecreationMoney = 0;
int selectIncomeUsage = 0;
//支出数据
float totalPayoutMoney = 0;
float pstudyMoney = 0;
float pcateringMoney = 0;
float pclothesMoney = 0;
float precreationMoney = 0;
void readData()
{
FILE* fp;///定义文件指针
if ((fp = fopen(fileName, "r")) == NULL)
{
fp = fopen(fileName, "w");
}
else
{
for (n = 0; !feof(fp); n++)
{
fscanf_s(fp, "%d %f %d %d %d %d %d %f %d %d %d %d\n", &payment[n].id, &payment[n].money, &payment[n].year, &payment[n].month, &payment[n].day, &payment[n].usage, &comement[n].id, &comement[n].money, &comement[n].year, &comement[n].month, &comement[n].day, &comement[n].usage);///将结构体里的信息写入文本
} ///保存文件数据到结构体
if (n == 0)
currentMaxId = 0;
else
currentMaxId = payment[n - 1].id;
}
fclose(fp);
}
//菜单选项
void menu()
{
int flag = 0;//中断程序的标志
while (flag)
{
readData();//重新加载文本数据
allPayoutMoneyCount();//计算当前金额总数
allIncomeMoneyCount();
system("cls");//清屏操作
int selectOPS;
cout << " |-------------------------------------------------|\n" << endl;
cout << " |----------- 欢迎进入个人财务管理系统 ----------- |\n" << endl;
cout << " |-------------------------------------------------|\n" << endl;
cout << " |\t\tIncome |\n" << endl;
cout << " |\t\t1.添加收入 |\n" << endl;
cout << " |\t\t2.查询收入明细 |\n" << endl;
cout << " |\t\t3.按类别查看收入 |\n" << endl;
cout << " |\t\t4.统计收入比例 |\n" << endl;
cout << " |-------------------------------------------------|\n" << endl;
cout << " |\t\tPayout |\n" << endl;
cout << " |\t\t5.添加支出 |\n" << endl;
cout << " |\t\t6.查询支出明细 |\n" << endl;
cout << " |\t\t7.按类别查看支出 |\n" << endl;
cout << " |\t\t8.统计支出比例 |\n" << endl;
cout << " |-------------------------------------------------|\n" << endl;
cout << " |\t\t0.退出系统 |\n" << endl;
cout << " |-------------------------------------------------|\n" << endl;
printf("请选择(0-8):[ ]\b\b");
selectOPS = numberJudge();
if (selectOPS < 0 || selectOPS>8)///错误输入,重新获取输入
{
printf("请确定好您要选择的服务,重新输入!!!\n");
system("pause");
menu();
}
else///正确输入
switch (selectOPS)///根据输入实现相应函数调用
{
case 1: add_income();
break;
case 2:search_income();
break;
case 3:selectIncomeByUsage();
break;
case 4:incomePercent();
break;
case 5:add_payout();
break;
case 6:search_payout();
break;
case 7:selectPaymentByUsage();
break;
case 8:paymentPercent();
break;
case 0:flag=0;
break;
}
}
}
/*内容过长无法放入*/
int main()
{
readData();///读取文件数据
char passw[] = "314";
char test[20] = "0";
int count = 0;//用来记录登录次数
while (count < 3)
{
printf("请输入密码->");
scanf_s("%s", &test,4);
if (strcmp(passw, test) == 0)
{
void menu();///显示主菜单
}
else
{
printf("密码错误\n");
count++;
}
}
if (3 == count)
{
printf("退出程序\n");
}
return 0;
}
三、运行结果
四、我的解答思路和尝试过的方法
1、把上面的main{}代换成
int main()
{
readData();///读取文件数据
menu();///显示主菜单
}
但是结果运行窗口没有任何显示
2、我把void menu 放到main{},结果提示报错
五、 我想要达到的结果
通过密码正确,正常进入 menu