been coding for a week how is this looking?

just wanted some feedback from some seasoned programmer i have only been at this for about a week i am teaching myself i think im getting a good understanding of the basics please let me know if there is any improvement that can be made

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include<iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <ctime>



using namespace std;



 
   int roll()
{  
       int R=0;
       int Dice1=1;
       int Dice2=1;
    
      Dice1=(rand() % 6)+1;
 
      Dice2=(rand() % 6)+1;
 
      R=Dice1+Dice2;
   
      return R;
}
 
   int bet(int b, int w)
{
     int bnk=0; 
 
       bnk=b-w;
 
         return bnk;
 
}
 
 
    int winbet(int wag)
{
     int win;
 
        win=wag*2;
     
          return win;
}
 
 
     
 
 
  
 
 
int main()
{

  int dice1=1;
  int dice2=1;
  int point;
  int newRoll=0;
  char keepRolling;
  int bank=100;
  int wager=0;
 srand(time(0));
  int Wins=0;
  int losses=0;
 
    
                           begin:
    cout << "Wins: " << Wins << endl << "Losses: " << losses <<endl;
     

    if(bank <= 0)
    {
     
    cout << "Game over.";
         
        exit(0);
     
    }
     
 
    cout << "bank= (" << bank << ")" << endl;
     cout << "Please place a bet between 1 and " << bank << endl;
      
       cin >> wager;
     
        if (wager>bank)
        {
          cout << "You dont have enough money to do this. please enter a different amount." << endl;
          
                     

        goto begin;
        }
 
      bank=bet(bank, wager);
     
       cout << bank << endl;
       
     
    point=roll();
 
 
    if(point==7||point==11)
    {
     cout << "Winner! with : " << point << endl;
 
     bank=bank+(wager*2);
  
       Wins++;
      

 
     goto begin;
    }
       
    if(point==2||point==3||point==12)
    {
     cout << "you crapped out with " << point << " better luck next time," << endl;

       losses++;
         
     goto begin;
    }
      
    else
    {
   if(point!=2||point!=3||point!=12)
     cout <<"Your point is "<< point << "\n Press enter to keep rolling"<< endl;
 
    cin.ignore();
     cin.get();
      
     goto Roll;
    }
        
     
   
    
 
   
   
                             rolling:
 
     cout << "would you like to keep playint? \n y/n" << endl;
   
       cin >> keepRolling;
 
    if(keepRolling=='y')
    {
      
    
     }
     else
     {
       //if(keepRolling=='n')
      
       exit(0);
      
     }
 
                               Roll: 
       
  roll();
 
 
     newRoll=roll();
 
     cout << "The new roll was " << newRoll << endl;
 
  if(newRoll==point)
  {
   cout << "We have a winner! ";
     
          Wins++;
       
        bank=bank+(wager*2);
  
      

         
         
        goto begin;
  }
 
  if(newRoll==7)
  {
   cout << "Pass the dice please." << endl;
         
         
        losses++;

        goto begin; 
  }
  else
  {
       goto rolling;
       
  }
 
 
 
 
 
    system ("PAUSE") ;
 
 
    return 0;
 
 
 
 
 }

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//Declare your secondary functions before main
//and define them after main.

int roll();
int bet(int b, int w);
int winbet(int wag);

int main()
{

	int dice1 = 1;
	int dice2 = 1;
	int point;
	int newRoll = 0;
	char keepRolling;
	int bank = 100;
	int wager = 0;
	srand(time(0));
	int Wins = 0;
	int losses = 0;

begin:
	
	//Splitting this up makes it easier to read
	cout << "Wins: " << Wins << endl; 
	cout << "Losses: " << losses << endl;

	if (bank <= 0)
	{
		cout << "Game over.";
		exit(0);
	}
	//Style point that some follow is always having an else for every if
	// even if it's an empty statement
	else
		;

	cout << "bank= (" << bank << ")" << endl;
	cout << "Please place a bet between 1 and " << bank << endl;
	cin >> wager;

	if (wager > bank)
	{
		cout << "You dont have enough money to do this. please enter a different amount." << endl;

		goto begin;
	}

	//Same as above
	else
		;

	bank = bet(bank, wager);

	cout << bank << endl;

	point = roll();
	
	if (point == 7 || point == 11)
	{
		cout << "Winner! with : " << point << endl;

		bank = bank + (wager * 2);
		Wins++;
		
		goto begin;
	}
	//You can use if elseif here. That way once something is true
	//The rest of the if's get skipped
	else if (point == 2 || point == 3 || point == 12)
	{
		cout << "you crapped out with " << point << " better luck next time," << endl;

		losses++;
		
               goto begin;
	}

	else
	{
		
		if (point != 2 || point != 3 || point != 12)
			cout << "Your point is " << point << "\n Press enter to keep rolling" << endl;
		else
			;
		
		cin.ignore();
		cin.get();

		goto Roll;
		
	}

rolling:

	cout << "would you like to keep playint? \n y/n" << endl;
	cin >> keepRolling;

	/*if (keepRolling == 'y')
	{


	}
	else
	{
		//if(keepRolling=='n')

		exit(0);

	}*/

	//Try this instead != is 'not equivalent to' also notice that for a single statement
        // {} are not needed. Cleans things up a lot.

	if (keepRolling != 'y')
		exit(0);
	else
		;

Roll:

	roll();
        
	newRoll = roll();

	cout << "The new roll was " << newRoll << endl;

	if (newRoll == point)
	{
		cout << "We have a winner! ";

		Wins++;
                bank = bank + (wager * 2);

		goto begin;
	}
	//else-if again
	else if (newRoll == 7)
	{
		cout << "Pass the dice please." << endl;
      
                losses++;

		goto begin;
	}
	else //single statement no {} needed
		goto rolling;
	
	system("PAUSE");
	
	return 0;
	
}

int roll()
{
	//Naming convention. Start with Lower-Case "dice1, dice2"
	
        int Dice1 = 1;
	int Dice2 = 1;

	Dice1 = (rand() % 6) + 1;
	Dice2 = (rand() % 6) + 1;
	
        //Return sum, no need for a var
	return Dice1 + Dice2;
}

int bet(int b, int w)
{

	// this works, no need for a var
	return b - w;

}

int winbet(int wag)
{
	//Same here
	return wag * 2;
}
Last edited on
What to fix:
1) gotos. There should be exact number of goto in your program: 0.
2) Formatting. thomaselder84 fixed it for you.
3) Overly long functions. If function does not fit on screen, it is too long.
4) Declare variables at the point of first use.
5) Use standard C++ facilities.
thank you guys for the detailed explanations they helped a lot much appreciated
Topic archived. No new replies allowed.