慢慢敲 2022-06-15 16:10 采纳率: 100%
浏览 234
已结题

vs中代码没有报错,但是代码没有运行完全

一、问题遇到的现象和发生背景
代码没有报错,但密码输入成功后没有继续运行,只是一直重复上一步

二、相关代码

#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;
}

三、运行结果

img

四、我的解答思路和尝试过的方法

1、把上面的main{}代换成

int main()
{
    readData();///读取文件数据
    menu();///显示主菜单
}

但是结果运行窗口没有任何显示

2、我把void menu 放到main{},结果提示报错

五、 我想要达到的结果

通过密码正确,正常进入 menu

  • 写回答

2条回答 默认 最新

  • 关注

    帮你重新弄了下,只是你有写函数并未实现。所以我注释起来了。你写完函数再放开

    #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 quit()
    {
    }
    
    int numberJudge()
    {
        return 0;
    }
    
    int usageJudge()
    {
        return 0;
    }
    
    
    
    //菜单选项
    void menu()
    {
        int flag = 1;//中断程序的标志
        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;
    
            int n = 0;
            scanf("%d", &n);   //这个阻塞下,不然会一直运行
    
            /*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;
                }*/
        }
    }
    
    void allPayoutMoneyCount()
    {
    }
    
    void allIncomeMoneyCount()
    {
    }
    
    /*内容过长无法放入*/
    
    
    int main()
    {
        //readData();///读取文件数据
        char passw[10] = "314";
        int count = 0;//用来记录登录次数
    
        while (count < 3)
        {
            char test[10];
            printf("请输入密码->");
            //scanf_s("%s", &test, 10);
            scanf("%s", &test);
            if (strcmp(passw, test) == 0)
            {
                 menu();///显示主菜单
            }
            else
            {
                printf("密码错误\n");
                count++;
            }
    
        }
        if (3 == count)
        {
            printf("退出程序\n");
        }
        return 0;
    }
    
    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)
    {
    }
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月4日
  • 已采纳回答 6月26日
  • 创建了问题 6月15日

悬赏问题

  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。