我无法弄清楚程序的问题,即使我查看了错误日志消息

问题描述 投票:-2回答:2

我的作业程序应该包含一个带有几个选项的菜单,第一个是猜谜游戏,第二个是在甲板上打印所有卡片等等。 (见下面的菜单)。我已经开始编写一些代码了,我已经测试了部分代码并且它们一直在工作。现在有了整个程序,我无法执行该程序。如果有人可以花一些时间来帮助解决这些问题以及其他必须包含的程序,我将不胜感激。以下错误消息不断出现:

Severity  Code    Description Project File    Line    Suppression State
Error (active)  E0120   return value type does not match the function type  ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 163 
___________________________________________
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings1_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 191 
____________________________________________
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings2_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 195 

Severity  Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings3_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 199 

Severity  Code    Description Project File    Line    Suppression State
Error   C1010   unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?   ConsoleApplication1 c:\users\ingrid\c++\consoleapplication1\consoleapplication1\consoleapplication1.cpp 219 
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <stdio.h>
#include <stdlib.h>     /* Imports srand and rand for the random generator in guess */
//*#include <stdafx.h>*//

using namespace std;

//*void guess_Menu();
//void card_Menu();
//void leap_Menu();
//void func_Menu();
//void settings_Menu;
//*void menu_check();

void main()
{
    int menu;

    cout << "***************************************************************************\n";
    cout << "***************************************************************************\n";
    cout << "####             Please Select From The Following Menu:              ######\n";
    cout << "####  Press 1 to play a guessing game                                ######\n";
    cout << "####  Press 2 to print all cards in a deck                           ######\n";
    cout << "####  Press 3 to display the leap year                               ######\n";
    cout << "####  Press 4 to calculate the function y = f(x)                     ######\n";
    cout << "####  Press 5 to check the settings (included color and language)    ######\n";
    cout << "####  Press 6 to exit the program                                    ######\n";
    cout << "***************************************************************************\n";
    cout << "***************************************************************************\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        guess_Menu();
        break;

    case 2:
        card_Menu();
        break;

    case 3:
        leap_Menu();
        break;

    case 4:
        func_Menu();
        break;

    case 5:
        settings_Menu();
        break;

    case 6:
        exit(0);
        break;

    default:
        std::cout << "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n";
        std::cout << "|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n";
        std::cout << "|          INVALID NUMBER - CHOOSE FROM 1 - 6      |\n";
        std::cout << "|__________________________________________________|\n";
        std::cout << " \t\t\t    PRESS ENTER TO CONTINUE ";
        cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
        cin.get();
        main();
    }

    system("pause");
}

void guess_Menu()
{
    int RandomNumber = rand() % 50 + 1; // to set the random number between 1-50
    int guesst = 15; // guess attempts as guesstaken or "guesst"
    int guess;
    const int Hnum = 50;
    const int Lnum = 1;

    void Again();
    {
        int decision = 0;
        bool TryAgain = true;
        char y;
        char Y;
        char n;
        char N;
    }

    cout << "Guess the random number between 1 and 50!\n";

    while (true)
    {
        cout << "You have " << guesst << " attempts remaining\n";
        cout << "Enter a number: ";
        cin >> guess;
        cin.ignore();
        cout << '\n';

        if (guess == RandomNumber)
        {
            cout << "Congratulations, you won: " << RandomNumber << "!";
            cout << "Would you like to play again y or n?";
            cin.get();
            void Again();
        }
        else if (guess < RandomNumber)
        {
            cout << "That guess is too low!\n";
        }
        else if (guess > RandomNumber)
        {
            cout << "That guess is too high!\n";
        }
        else if (guess > Hnum || guess < Lnum)
        {
            cout << "Guess must be lower than 50 and higher than 1, Try again\n";
            cin.get();//remove this to count guesses that are outside the 1-50
        }
        guesst--;

        if (guesst == 0)
        {
            cout << "You did a lowzy work trying to guess the number. The correct number was... " << RandomNumber << "!";
            cout << "\n";
            cin.get();
            void Again();
        }
    }
}


void card_Menu()
{
    printf("Hello World!");
}

void leap_Menu()
{
    int year;

    cout << "Enter a year: ";
    cin >> year;

    if (year % 4 == 0)
    {
        if (year % 100 == 0)
        {
            if (year % 400 == 0)
                cout << year << " is a leap year.";
            else
                cout << year << " is not a leap year.";
        }
        else
            cout << year << " is a leap year.";
    }
    else
        cout << year << " is not a leap year.";

    return 0;
}



void func_Menu()
{

    cout << "Blabla\n";
}



void settings_Menu()
{
    int menu;
    cout << "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n";
    cout << "||          Please Select From The Following Menu           ||\n";
    cout << "||  1. Settings, choose this to change color                ||\n";
    cout << "||  2. Settings, choose this to language                    ||\n";
    cout << "||  3. Exit the program                                     ||\n";
    cout << "||   <------------------            ------------------>     ||\n";
    cout << "||__________________________________________________________||\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        settings1_Menu();
        break;

    case 2:
        settings2_Menu();
        break;

    case 3:
        settings3_Menu();
        break;

    default:
        cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
        cout << "§                                                §\n";
        cout << "^      INVALID NUMBER - CHOOSE FROM 1 - 3        §\n";
        cout << "^________________________________________________^\n";

        cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
        cin.get();
        main();
    }
}
c++ visual-c++ menu submenu multiple-choice
2个回答
0
投票

错误1:第163行

return 0;为无效功能。

错误2-4:第191,195,199行

settings1_Menu()
settings2_Menu()
settings3_Menu()

没有定义。

正如读取的错误一样。

不确定预编译的头文件问题,我根本没有真正使用它们,并且该错误不在我的VS2015中。

此外,您已将注释掉的函数声明

//*void guess_Menu();
//void card_Menu();
//void leap_Menu();
//void func_Menu();
//void settings_Menu;
//*void menu_check();

阻止定义的编译,settings_Menu需要settings_Menu()和menu_check()是未定义的。


0
投票

您在lead_menu函数中有错误

void leap_Menu()
{
    ...
    return 0;
}

您还可以将所有原型注释掉。因此,当编译器到达函数调用时,它不知道函数是什么。如果您不想使用原型,请查看内联函数

© www.soinside.com 2019 - 2024. All rights reserved.