Need help for a game

hi, guys, I'm having trouble in running my code. my first problem was that the winner was not always showing so I try to add if statement to declare the winner. then, I added a do while in order to restart the game and the return 0 shows an error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
//System Libraries
#include <iostream>  //Input/Output Library
#include <string> // 
#include<fstream> //
#include <cstdlib> // Random Function
#include <ctime> // Time function
#include <iomanip> // format function
using namespace std;

//User Libraries

//Global Constants, no Global Variables are allowed
//Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...

//Function Prototypes

//Execution Begins Here!
int main(int argc, char** argv) {
    do {
    srand(static_cast<unsigned int>(time(0)));//seed random number generator
    //The main menu of the game 
    char ans;
    string P1,P2;      // the names of players
    float bet; // the bet for the  game
   
    
    cout<<"Welcome to street craps\n"<<endl;
    cout<<"Enter player 1 and players 2 a.k.a the shooter Names"<<endl;
    cin>>P1;       // the name of player 1
    cin>>P2;       // the name of player 2
    cout<<"\n";    // add a new line
    cout<<"shooter make bet"<<endl; 
    cin>>bet;      // the money that is being bet
    while(cin && bet < 1.0f) // checks if the money being bet is more than a dollar 
    {
        cout<< "The minimum bet is $1.00 Please place a higher bet." <<endl;
	    cin >> bet;
    } if(!cin){      // make sure for a valid input
        cout<< "input invalid."<<endl;
        
    }
   
    // declare vaules
    char die1=rand()%6+1;//[1,6] dice 1
    char die2=rand()%6+1;//[1,6] dice 2
    char sum=die1+die2; // adds both dice to get sum
    
    // the logic of the game
   if(sum==7 || sum==11){    // checks the sum of dice roll 7 or 11
       cout<<P2<<"  wins $"<<bet<<endl;
   }
   else if(sum==2){  // checks if the sum of the eyes roll 2
            cout<<P1<<"  wins $"<<bet<<endl;
        }
        else if(sum==3){   // checks if the sum of the eyes roll 2
            cout<<P1<<"  wins $"<<bet<<endl;
        }
        else if(sum==12){   // checks if the sum of the eyes roll 2
            cout<<P1<<"  wins $"<<bet<<endl;
        }
        else{            // checks if the dice roll any other number
            bool rollAgn;
            do{
                die1=rand()%6+1;//[1,6] dice 1
                die2=rand()%6+1;//[1,6] dice 2
                char sumAgn=die1+die2;  // the sum of the dice being roll again
                if(sumAgn==7){    // checks if sum of dice if 7
                    P2;rollAgn=false;
                    cout<<P1<<"  wins $"<<bet<<endl;
                } 
                else if(sum==sumAgn){ // checks if the sum and the roll again is the same
                    P2;rollAgn=false;
                    cout<<P2<<"  wins $"<<bet<<endl;
                }  
                else rollAgn=true;  // makes the dice roll again if the sum of the dice roll any other dice
             }  while (rollAgn);             
             cout<<"Another game? Y(es) or N(o)"  << endl;
    cin >> ans;
         while ((ans == 'N') && ( ans == 'n')){
             cout<<"thank for playing"<<endl;
             cin>> ans;
         }
            }
}
    //Exit stage right or left!
return 0; 
}

        


my error

main.cpp: In function 'int main(int, char**)':
main.cpp:93:8: error: expected 'while' before numeric constant
return 0;
^
main.cpp:93:8: error: expected '(' before numeric constant
main.cpp:93:9: error: expected ')' before ';' token
return 0;
^
Last edited on
This is why clear indentation matters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//System Libraries
#include <iostream>             //Input/Output Library
#include <string>               //
#include<fstream>               //
#include <cstdlib>              // Random Function
#include <ctime>                // Time function
#include <iomanip>              // format function
using namespace std;

//User Libraries

//Global Constants, no Global Variables are allowed
//Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...

//Function Prototypes

//Execution Begins Here!
int main(int argc, char **argv)
{
  do {
    srand(static_cast < unsigned int >(time(0))); //seed random number generator
    //The main menu of the game
    char ans;
    string P1, P2;              // the names of players
    float bet;                  // the bet for the  game


    cout << "Welcome to street craps\n" << endl;
    cout << "Enter player 1 and players 2 a.k.a the shooter Names" << endl;
    cin >> P1;                  // the name of player 1
    cin >> P2;                  // the name of player 2
    cout << "\n";               // add a new line
    cout << "shooter make bet" << endl;
    cin >> bet;                 // the money that is being bet
    while (cin && bet < 1.0f)   // checks if the money being bet is more than a dollar
    {
      cout << "The minimum bet is $1.00 Please place a higher bet." << endl;
      cin >> bet;
    }
    if (!cin) {                 // make sure for a valid input
      cout << "input invalid." << endl;

    }
    // declare vaules
    char die1 = rand() % 6 + 1; //[1,6] dice 1
    char die2 = rand() % 6 + 1; //[1,6] dice 2
    char sum = die1 + die2;     // adds both dice to get sum

    // the logic of the game
    if (sum == 7 || sum == 11) {  // checks the sum of dice roll 7 or 11
      cout << P2 << "  wins $" << bet << endl;
    } else if (sum == 2) {      // checks if the sum of the eyes roll 2
      cout << P1 << "  wins $" << bet << endl;
    } else if (sum == 3) {      // checks if the sum of the eyes roll 2
      cout << P1 << "  wins $" << bet << endl;
    } else if (sum == 12) {     // checks if the sum of the eyes roll 2
      cout << P1 << "  wins $" << bet << endl;
    } else {                    // checks if the dice roll any other number
      bool rollAgn;
      do {
        die1 = rand() % 6 + 1;  //[1,6] dice 1
        die2 = rand() % 6 + 1;  //[1,6] dice 2
        char sumAgn = die1 + die2;  // the sum of the dice being roll again
        if (sumAgn == 7) {      // checks if sum of dice if 7
          P2;
          rollAgn = false;
          cout << P1 << "  wins $" << bet << endl;
        } else if (sum == sumAgn) { // checks if the sum and the roll again is the same
          P2;
          rollAgn = false;
          cout << P2 << "  wins $" << bet << endl;
        } else
          rollAgn = true;       // makes the dice roll again if the sum of the dice roll any other dice
      } while (rollAgn);
      cout << "Another game? Y(es) or N(o)" << endl;
      cin >> ans;
      while ((ans == 'N') && (ans == 'n')) {
        cout << "thank for playing" << endl;
        cin >> ans;
      }
    }
  }
  //Exit stage right or left!
  return 0;
  }


$ indent -kr -nut -ts2 -i2 -l120 -cli0 foo.cpp
indent: foo.cpp:87: Error:Stmt nesting error.
indent: foo.cpp:88: Error:Unexpected end of file


Yes, you really are missing at least one closing brace.
And since the very first thing in main is a 'do', then the compiler complaining about 'expected while' is entirely appropriate.
Topic archived. No new replies allowed.