我的代码无法解决问题。我正试图通过按键盘上的任何键但不按下输入来退出do。我的代码段在下面。
void LemonadeBuyANDCheck()
{
int iCupsToBuy = rand() % (MAX_CUPS - MIN_CUPS) + MIN_CUPS;
bool continueLoop = true;
do
{
int Userinput = 1;
Userinput = !_kbhit();
fflush(stdin);
if (Userinput == 1)
{
continueLoop = false;
}
StoreIsOpen();
int randomNumber = rand() % 100;
if (iCupsOfLemonadeInStock == 0)
{
cout << "Customer came to buy some lemonade but you didnt have any in stock :(\n";
//continueLoop = false;
}
else if (randomNumber <= 25)
{
cout << "Wow your lemonade is way too expensive!\n";
iCustomerCounter++;
}
else if (randomNumber >= 75)
{
cout << "Eww your recipe for lemonade... Wow..\n";
iCustomerCounter++;
}
else if (iCupsOfLemonadeInStock >= iCupsToBuy)
{
cout << "You sold " << iCupsToBuy << "cups of lemonade!\n";
iCupsOfLemonadeInStock = iCupsOfLemonadeInStock - iCupsToBuy;
iCupsOfLemonadeSold = iCupsOfLemonadeSold - iCupsToBuy;
//Money
fMoneyEarned += (iCupsToBuy * fCurrentLemonadePrice);
fCurrentMoney += (iCupsToBuy * fCurrentLemonadePrice);
iCustomerCounter++;
}
else if (iCupsOfLemonadeInStock < iCupsToBuy)
{
cout << "You didnt have enough lemonade in stock so you only sold " << iCupsToBuy - iCupsOfLemonadeInStock << endl;
fMoneyEarned += (iCupsOfLemonadeInStock * fCurrentLemonadePrice);
fCurrentMoney += (iCupsOfLemonadeInStock * fCurrentLemonadePrice);
iCupsOfLemonadeInStock = 0;
iCustomerCounter++;
}
} while (continueLoop != true);
fflush(stdin);
GameMenuSelectionVerifier();
}
答案 0 :(得分:0)
我认为你可以使用一个名为&#34; kbhit&#34;的函数,它在&#34; conio.h&#34;头文件。您可以点击this了解详情。你可以像这样修改它:
$result=array();
$key='sub';
foreach($this->Click_model->getClickStream() as $row)
{
$result[$row['id_click']]['sub'][]= $row['id_kampanye'].$row['code'];
$newResult=array_column($result,$key);
file_put_contents ('datasetArray.txt', print_r($newResult, true));
$arrLength=count($newResult);
}
for($x=0;$x<$arrLength;$x++){
file_put_contents ('dataset.txt', implode(',',$newResult[$x])."\n", FILE_APPEND);
}