更新2:好吧,我修好了,原来这是一个简单的问题,半柱进入它不属于的地方,正在寻找完全错误的地方。
更新:删除一些注释修复了 cin cout 错误,现在唯一的错误应该是在左括号和右括号上的声明,并且一个出现在 else 语句中。
错误“预期声明”出现在函数 playeroneturn 的开始和结束 {} 以及函数中 if 语句的结束 } 中,也在 if 语句中 cin 和 cout 都给出错误“这个声明没有存储类或类型说明符”
#include "stdafx.h"
#include "iostream"
#include "ctime"
#include "cstdlib"
#include "string"
//prototype function declaration from stackoverflow.com/questions/2575153/must-declare-function-prototype-in-c
int help(int menu);
int start(int menu);
int oneplaymode();
int playeroneturn();
int playertwoturn();
//function start is called to display the games menu screen
int start(int menu)
{
using std::cout;
using std::cin;
using std::endl;
cout << "#########################################################################" << endl;
cout << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t PIGS\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t1. 1 Player\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t2. 2 Player\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t3. help\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl;
cout << "#########################################################################" << endl;
cout << "enter number for your selection: ";
cin >> menu;
if(menu == 1)
{
cout << "single-player not yet implemented" << endl;
}
else if(menu == 2)
{
int twoplayermode();
}
else if(menu == 3)
{
help(menu);
}
else
{
cout << "Error: Please choose a valid option" << endl;
start(menu);
}
return(menu);
}
int help(int menu)
{
using std::cout;
using std::endl;
cout << "#########################################################################" << endl;
cout << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t HELP\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "# The objective of pigs is to be the first to score 100.\t\t#" << endl << "# Each turn you must roll a die then pass or roll again.\t\t#" << endl << "# You must then choose to ROLL again or END your turn.\t\t\t#" << endl << "# At the end of your turn your total is added to your score.\t\t#" << endl << "# However if you roll a 1 your turn ends and you score 0.\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl << "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl<< "#\t\t\t\t\t\t\t\t\t#" << endl;
cout << "#########################################################################" << endl;
system("pause");
start(menu);
return 0;
}
int playeroneturn(int p1score);
{
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::srand;
using std::rand;
using std::time;
using std::string;
srand((unsigned int)time(0));
int roll = 0;
int p1score = 0;
string reroll = "roll";
while(reroll == "roll")
{
roll = 1 + (rand() % 6);
if(roll > 1)
{
p1score = p1score+roll;
// using " in a string msdn.microsoft.com/en-us/library/267k4fw5.aspx
cout << "You rolled a " << roll << endl << "Type roll to roll again or end to end your turn."; // error on cout this declaraton has no storage class or type specifier and error on first << expected a ;
cin >> reroll;
}
else
{
cout >> "Bad luck! you rolled a 1, your turn is over and you score nothing!"
p1score = 0;
reroll = end;
}
}
return p1score;
}