You should work more on formatting..
Here (your 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
|
#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(){
short unsigned int score1 = 0;
short unsigned int compScore1 = 0;
short unsigned int compScore2 = 0;
short unsigned int compScore3 = 0;
short unsigned int compScore4 = 0;
short unsigned int compScore5 = 0;
short unsigned int num1 = 0;
short unsigned int num2 = 0;
short unsigned int compNum1 = 0;
short unsigned int compNum2 = 0;
short unsigned int compNum3 = 0;
short unsigned int compNum4 = 0;
short unsigned int compNum5 = 0;
short unsigned int sum = 0;
short unsigned int compSum1 = 0;
short unsigned int compSum2 = 0;
short unsigned int compSum3 = 0;
short unsigned int compSum4 = 0;
short unsigned int compSum5 = 0;
char letter;
//Declare Variables
srand(time(NULL));
//Initialize random number generator
while (letter != 'x'){
cout << "Your Score: " << score1 << endl;
cout << "computer 1 Score: " << compScore1 << endl << endl;
cout << "computer 2 score:" << compScore2 << endl << endl;
cout << "computer 3 score:" << compScore3 << endl << endl;
cout << "computer 4 score:" << compScore4 << endl << endl;
cout << "computer 5 score:" << compScore5 << endl << endl;
cout << "Press r to roll or x to quit: ";
cin >> letter;
num1 = 1 + rand() % (6 - 1 + 1);
num2 = 1 + rand() % (6 - 1 + 1);
compNum1 = 1 + rand() % (6 - 1 + 1);
compNum2 = 1 + rand() % (6 - 1 + 1);
compNum3 = 1 + rand() % (6 - 1 + 1);
compNum4 = 1 + rand() % (6 - 1 + 1);
compNum5 = 1 + rand() % (6 - 1 + 1);
//Random numbers
sum = num1 + num1;
compSum1 = compNum1 + compNum1;
compSum2 = compNum2 + compNum2;
compSum3 = compNum3 + compNum3;
compSum4 = compNum4 + compNum4;
compSum5 = compNum5 + compNum5;
//Calculate Sums
if (letter == 'x') break;
if (letter != 'r'){
system("cls");
continue;
}
switch (num1,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
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: " << num1 << ", " << num2 << endl;
cout << "Computer 1 " << compNum1 << ", " << compNum1 << "\n\n";
cout << "Computer 2 " << compNum2 << ", " << compNum2 << "\n\n";
cout << "computer 3 " << compNum3 << ", " << compNum3 << "\n\n";
cout << "computer 4 " << compNum4 << ", " << compNum4 << "\n\n";
cout << "computer 5 " << compNum5 << ", " << compNum5 << "\n\n";
//Display dice and numbers
if (sum > compSum1)
{
compScore1++;
}
if (sum > compSum2)
{
compScore2++;
}
if (sum > compSum3)
{
compScore3++;
}
if (sum> compSum4)
{
compScore4++;
}
if (sum > compSum5)
{
compScore5++;
}
cout << "DICEY YOU WON" << endl << endl;
score1++;
{
cout << "WAWAWAWAAAAAAAA You Lost!" << endl << endl;
}
//Calculate score
system("pause");
system("cls");
if (score1 == 12){
MessageBox(0, "DICEY YOU WON!", "Results:", MB_ICONEXCLAMATION);
break;
}
if (compScore1 == 12)
if (compScore2==12)
if (compScore3==12)
if (compScore4==12)
if (compScore5==12){
MessageBox(0, "WAWAWAAAAAAAAa", "Results:", MB_ICONEXCLAMATION);
break;
}
}
return 0;
}
void one(){
cout << "1" << endl;
}
void two(){
cout << "2" << endl;
}
void three(){
cout <<"3" << endl;
}
void four(){
cout << "4" << endl;
}
void five(){
cout << "5" << endl;
}
void six(){
cout << "6" << endl;
}
|
I compiled it and got no run time error. It is a bad code though..
line 2 should be ctime.
lines 17-40. lots of repetitions here. you should use arrays here. also, note that while human player has two variables for dice rolls, computer players only have one each.
lines 51-77. again, lots of repetitions. if you used arrays, you could fit write in few lines using a for loop. also, note that sum is the first dice * 2, which makes no sense..
line 90. num1, num2 is not what you think (whatever you think..). it is equivalent to num2.
lines 90-135. firstly, they serve no purpose. there is no need to show those rolls since you're showing them on line 138 anyway. also, the switch is not needed. cout << num1 << " " << num2; would have worked.
lines 147-166. you give your opponents points for rolling less than you? what you should be doing is finding which one rolled the most. again, an array would make this simple.
lines 168, 173. you both win and loose simultaneously.. you really need some conditions here.
lines 187-191. when you put ifs one after another, you get "if condition 1 and condition 2 and ... then". I'm not sure if that was the intention.
lines 201-223. these functions are not needed at all as "cin << number" will do this for you.
good luck.