c++ - Id 退出状态的问题
问题描述
这是我第一次发帖,我迫切需要帮助。我正在尝试编写一个程序来为学校运行 Craps,但我遇到了标题中列出的错误。我环顾四周并给我的教授发了信息,做了他要求的一切,但仍然没有解决它。与其再纠缠他,谁能帮我弄清楚下一步该怎么做?
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
const int win1=7;
const int win2 =11;
const int crap1=2;
const int crap2=3;
const int crap3=12;
//prototypes for 5 functions are below, you need to code the bodies for these functions down below the main routine
int rollTheDice();
bool flag = false ;
bool winner( int );
bool craps( int );
void rollMore( int, double );
double getWager();
int diceRoll,dice1,dice2,roll,point;
double wager;
int main()
{
srand(34); //the final run will have 34, seed of 6 rolls a 7 -automatic winner, seed of 36 rolls 2-loser
cout << fixed << setprecision(2); //set output format
wager = getWager(); // call get wager and get back the amount the player wagered
cout<< "The amount wagered is "<<wager<<endl<<endl; //i added this cout to verify what wager is returned from getWager()
diceRoll = rollTheDice();
if( winner(diceRoll) ==true )
{
cout << "\nCongratulations! You have won " << wager << " $ \n";
}
else if( craps(diceRoll)==true) //call function craps and test if true is returned
{
cout << "\nSorry! You have lost " << wager << " $ \n";//print loser message and amount loss
}
else
{
rollMore( diceRoll, wager );
}
return 0;
//Get the user's wager amount with a cin and verify it before returning the value to main
double getWager()
{
cout << "Please enter your initial bet, in whole dollar amounts. The starting bet is 5.00$. \n" ;
cin >> wager ;
while (wager < 5)
{
cout << "I am sorry, the number you have entered is an insufficient bet. Please Try Again \n" ;
cin >> wager;
}
return wager;
}
int rollTheDice() //method is called and returns the roll of two dice, value between2-12
{ //you need two dice variables and generate a random number between 1-6 for each dice
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
diceRoll = dice1 + dice2;
roll=diceRoll;
cout << "You have rolled a " << diceRoll <<" \n";
return roll;
}
bool winner( int roll ) //returns true if roll is 7 or 11,else return false
{
if (roll==win1 or roll==win2)
{
return true;
}
else return false;
}
bool craps( int roll ) //returns true if player craps out which is a roll is 2,3,12,
if (roll==crap1 or roll==crap2 or roll==crap3)
return true ;
else return false ;
}
void rollMore( int point, int diceRoll, double wager, bool flag )
{
point=diceRoll;
cout << "You did not win or lose! We are now rolling to match the point by rolling " << point << "\n";
while (flag=false)
{
diceRoll = rollTheDice();
if (diceRoll==7)
cout << "\nSorry! You have lost " << wager << " $ \n";
flag == true ;
if (diceRoll=point)
cout << "\nCongratulations! You have won " << wager << " $ \n";
flag==true;
}
}
解决方案
推荐阅读
- php - 在数组上添加前一个值 - PHP
- flutter - 无法在颤振中使用 MultipartFile 发送文件
- python - 组合多个csv的有效方法
- mongodb - 为每个获取请求获取“_id:000000000”
- jquery - 旧 jquery 版本 (1.12) 的 Select2 库 - 我可以使用什么版本?
- flutter - 在 FutureBuilder 工作时从另一个 API 获得响应
- python - 将不同的变量与不同的日期相关联 - datetime pandas - Python
- google-sheets - 如何使用全行条件格式否定“isblank”函数
- jira - 如何制作“参数化”JQL
- xaml - 如何在 WinUI3 页面中使用静态资源?