我的家庭作业程序应该包含一个带有几个选项的菜单,第一个是猜谜游戏,其次,将所有卡片打印在卡座3中……等等。 (请参阅下面的菜单)。我已经开始编写一些代码,并且已经测试了部分代码,并且它们一直在工作。现在,使用下面的整个程序,我无法执行该程序。如果有人能抽出一些时间来帮助解决问题以及可能包括的其他必备程序,我将不胜感激。不断出现以下错误消息:
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();
}
}
答案 0 :(得分:0)
错误1:第163行
return 0;
用于void函数。
错误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()未定义。
答案 1 :(得分:0)
lead_menu函数出现错误
void leap_Menu()
{
...
return 0;
}
您还注释掉了所有原型。因此,当编译器到达函数调用时,它不知道函数是什么。如果您不想使用原型,请查看内联函数