我试图编写一个Pick'em应用程序,用户选择哪个团队将赢得锦标赛中每个ROUND游戏。 I.E锦标赛有多轮比赛,我每轮计算获胜者并记录胜利。
我目前正在努力让胜利者在一轮结束时
我解决上述问题的逻辑如下:
我有一个DB结构部分看起来像这样
我在下面发布我的代码,我希望有人可以指出我哪里出错了。
我可以确认以下
void playercheck()
{
cout << "It is Player: " << PlayerPiece << " Turn, please put select a piece on the board" << endl;
cin >> playerchoice;
//while the input it less than 1, more than 9, or NOT an integer
while (playerchoice < 1 || playerchoice > 9 || cin.fail())
{
cout << "You did not enter an appropriate response." << endl;
cout << "Please, enter in a digit between 1 and 9." << endl;
//clear the input flag on the stream so we can recheck cin.fail()
cin.clear();
//skip up to 256 characters in the pursuit of skipping to the next newline
cin.ignore(256, '\n');
cin >> playerchoice;
}
playerinput(playerchoice);
}
)// ### STEP 1 ###
Uninitialized string offset
坚持了几个小时任何帮助或建议非常感谢
答案 0 :(得分:1)
假设您的第一个查询只返回一个事件,您可以找到谁选择正确的团队:
//GET EVNT INFO
$sql = "SELECT * FROM events WHERE tournament = 'IPL' AND round = '5'";
$query = $db->query($sql);
// Store the event info inside an array.
$event = $query->fetch(PDO::FETCH_ASSOC);
//### STEP 2 ###
//GET MEMBER SELECTIONS
$sql = "SELECT * FROM multiple_picks WHERE tournament = 'IPL' AND round ='5' ORDER BY round_game_nr";
$query = $db->query($sql);
// Store members inside a collection of member.
$picks = $query->fetchAll(PDO::FETCH_ASSOC);
//### STEP 3 ###
//GET Winning Teams
$winner = null;
if ($event['team1Score'] > $event['team2Score']) {
$winner = $event['team1'];
} elseif ($event['team1Score'] < $event['team2Score']) {
$winner = $event['team2'];
}
// ### STEP 4 GET MEMBERS WHO SELECTED CORRECT TEAM ###
//GET WINNING MEMBERS
$correct = [];
foreach ($picks as $pick) {
if ($pick['pick'] === $winner) {
$correct[] = $pick['member_nr'];
echo 'Member ' . $pick['member_nr'] . ' picks correctly !';
}
}