首页 > 解决方案 > 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;
    }
}

标签: c++compiler-errors

解决方案


推荐阅读