Dice game?!!?I need help with EVERYTHING!!

Pages: 12
HI EVERYONE

Okay I worked really hard and this is what I got so far!!

PLEASE WOULD YOU BE SO KIND TO HELP ME WITH THE CODE ON HOW TO DECIDE THE WINNERS?!!?!


4- The winner is decided as follows:

a. If neither of the outcomes are a double such as ‘1-1’ or ’2-2’ or ’3-3’ or ‘4-4’ or ‘5-5’ or ‘6-6’ one of player 1 with the larger total wins, and if the totals are equal, it is a draw

b. If one outcome is a double, and the other is not, the player with a double wins and the totals will be irrelevant

c. If both outcomes are a double, then the player with the higher double wins, and if the doubles are equal, it is a draw

Please help me with deciding the winners code that's the most vital!!

ALSO,, my game is playing with the computer how do I change it to two players???

THE CODE SO FAR!!!




#include <iostream>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
void one();
void two();
void three();
void four();
void five();
void six();
//Declare Functions used
int main()
{
int score = 0;
int compScore = 0;
int num = 0;
int num2 = 0;
int compNum = 0;
int compNum2 = 0;
int sum = 0;
int compSum = 0;
char letter;
//Declare Variables
srand(time(NULL));
//Initialize random number generator
system("title Joe's Dice Game");
while (letter != 'q')
{
cout << "Your Score: " << score << endl;
cout << "computer's Score: " << compScore << endl << endl;
cout << "Press r to roll or q to quit: ";
cin >> letter;
num = 1 + rand() % (6 - 1 + 1);
num2 = 1 + rand() % (6 - 1 + 1);
compNum = 1 + rand() % (6 - 1 + 1);
compNum2 = 1 + rand() % (6 - 1 + 1);

//Random numbers

sum = num + num2;
compSum = compNum + compNum2;

//Calculate Sums

if (letter == 'q')
break;
if (letter != 'r')
{
system("cls");
continue;
}

switch (num)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout << "Error...";
break;
} //end switch

switch (num2)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout << "Error...";
break;
} //end switch

cout << endl << "Yours: " << num << ", " << num2 << endl;
cout << "Computer's: " << compNum << ", " << compNum2 << "\n\n";

//Display dice and numbers

if (sum > compSum)
{
cout << "You won!!" << endl << endl;
score++;
}
else
{
compScore++;
cout << "you lost..." << endl << endl;
}

//Calculate score

system("pause");
system("cls");

if (score == 12)
{
MessageBox(0, "You Won!!!", "Results:", MB_ICONEXCLAMATION);
break;
}
if (compScore == 12)
{
MessageBox(0, "You lost...", "Results:", MB_ICONEXCLAMATION);
break;
}
}
return 0;
}

void one()
{
cout << " -----" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " -----" << endl;
}
void two()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void three()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| O |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void four()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void five()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| O |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void six()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}


P.S PLEASE HELP I DID WHAT YOU GUYS ASKED
I WROTE THE CODES!!!
HELP WITH THE LAST PART (DECIDING WINNERS
Off of the intended topic, as a mechanical engineer programming is VERY important! If you want to confirm an equation you've written, MATLAB is an engineer's best friend where you'll need to learn to code. You'll often need to tune in code to get a finite element analysis to work, or you will undoubtedly need to design/run simulations on the parts you design. Programming is very important to an engineering career. The specific language may not be so important, but the mentality that you need a function here, make a loop there, and organize my programs like so is a fundamental skill that you will require.

On topic, the logic is actually laid out right there. You just need to put it into code:
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
217
218
219
220
221
222
223
224
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;

void one();
void two();
void three();
void four();
void five();
void six();

//Declare Functions used
int main()
{
    int score = 0;
    int compScore = 0;
    int num = 0;
    int num2 = 0;
    int compNum = 0;
    int compNum2 = 0;
    int sum = 0;
    int compSum = 0;
    char letter;
    //Declare Variables
    srand(time(NULL));
    //Initialize random number generator
    system("title Joe's Dice Game");
    while (letter != 'q')
    {
        cout << "Your Score: " << score << endl;
        cout << "computer's Score: " << compScore << endl << endl;
        cout << "Press r to roll or q to quit: ";
        cin >> letter;
        num      = 1 + rand() % 6;
        num2     = 1 + rand() % 6;
        compNum  = 1 + rand() % 6;
        compNum2 = 1 + rand() % 6;

        //Random numbers
        sum = num + num2;
        compSum = compNum + compNum2;

        //Calculate Sums

        if (letter == 'q')
            break;
        if (letter != 'r')
        {
            system("cls");
            continue;
        }

        switch (num)
        {
        case 1:
            one();
        break;
        case 2:
            two();
        break;
        case 3:
            three();
        break;
        case 4:
            four();
        break;
        case 5:
            five();
        break;
        case 6:
            six();
        break;
        default:
            cout << "Error...";
        break;
        } //end switch

        switch (num2)
        {
        case 1:
            one();
        break;
        case 2:
            two();
        break;
        case 3:
            three();
        break;
        case 4:
            four();
        break;
        case 5:
            five();
        break;
        case 6:
            six();
        break;
        default:
            cout << "Error...";
        break;
        } //end switch

        cout << endl << "Yours: " << num << ", " << num2 << endl;
        cout << "Computer's: " << compNum << ", " << compNum2 << "\n\n";

        //Display dice and numbers

        if (sum > compSum)
        {
            cout << "You won!!" << endl << endl;
            score++;
        }
        else
        {
            compScore++;
            cout << "you lost..." << endl << endl;
        }

        //Calculate score
        system("pause");
        system("cls");

        int winner; // 0 = you, 1 = Computer, 2 = draw

        // 4 a 
        if (num != num2 && compNum != compNum2) // No doubles
        {
            if (sum > compSum) // Highest sum wins
                winner = 0;
            else if (sum < compSum)
                winner = 1;
            else
                winner = 2;
        }
        // 4 c
        else if (num == num2 && compNum == compNum2) // Both are doubles
        {
            if (num > compNum) // Highest doubles win
                winner = 0;
            else if (num < compNum)
                winner = 1;
            else
                winner = 2;
        }
        // 4 b
        else // One set is a double
        {
            if (num == num2) // The one with the doubles wins.
                winner = 0;
            else
                winner = 1;
        }

        if (winner == 0)
        {
            MessageBoxA(0, "You Won!!!", "Results:", MB_ICONEXCLAMATION);
            break;
        }
        else if (winner == 1)
        {
            MessageBoxA(0, "You lost...", "Results:", MB_ICONEXCLAMATION);
            break; 
        }
        else 
        {
            MessageBoxA(0, "Draw...", "Results:", MB_ICONEXCLAMATION);
            break;
        }

    }
    return 0;
}

void one()
{
    cout << "-----" << endl;
    cout << "|   |" << endl;
    cout << "| O |" << endl;
    cout << "|   |" << endl;
    cout << "-----" << endl;
}
void two()
{
    cout << "-----" << endl;
    cout << "| O |" << endl;
    cout << "|   |" << endl;
    cout << "| O |" << endl;
    cout << "-----" << endl;
}
void three()
{
    cout << "-----" << endl;
    cout << "|  O|" << endl;
    cout << "| O |" << endl;
    cout << "|O  |" << endl;
    cout << "-----" << endl;
}
void four()
{
    cout << "-----" << endl;
    cout << "|O O|" << endl;
    cout << "|   |" << endl;
    cout << "|O O|" << endl;
    cout << "-----" << endl;
}
void five()
{
    cout << "-----" << endl;
    cout << "|O O|" << endl;
    cout << "| O |" << endl;
    cout << "|O O|" << endl;
    cout << "-----" << endl;
}
void six()
{
    cout << "-----" << endl;
    cout << "|O O|" << endl;
    cout << "|O O|" << endl;
    cout << "|O O|" << endl;
    cout << "-----" << endl;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 12