Byte Limit Problem

Hi, I was working on a project, and I exceeded the byte limit (65,536 bytes), and I'm hardly done! I used lots of if and elseif statements, so I'm wondering if that has something to do with it. Can you give me any tips on how to lower the file size? Thanks! And, also, the partial code's below (I shortened it due to forum character-limit):


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


char start, yourmove;
short int onum = rand() % 5 + 1;
char omove[5] = {'a', 'm', 'h', 's', 'w'};
short int yourrehealth = 45;
short int o1rehealth = 20;

void battle1(){
  cout << "Choose your move (press 'a' to attack with your sword, 'm' to attack with magic, 'h' to heal yourself, 's' to defend with your shield, or 'w' to defend with your wand)!" << endl;
  cin >> yourmove;
  if (yourmove == 'a'){
    cout << "You attacked with your sword!" << endl;
    int onum = rand() % 5 + 1;
    if (onum == 1){
      
      yourrehealth = 42;
      o1rehealth = 22;
      cout << "The Death Eater also attacked with its sword!" << endl << endl << "You both lose 3 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " ." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 2){
      
      yourrehealth = 41;
      o1rehealth = 22;
      cout << "The Death Eater attacked with its wand!" << endl << endl << "You lose 4 damage, while the Death Eater loses 3 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 3){
      
      yourrehealth = 42;
      o1rehealth = 25;
      cout << "The Death Eater defended with its shield!" << endl << endl << "You lose 3 damage as backlash, while the Death Eater is unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 4){
      
      yourrehealth = 45;
      o1rehealth = 22;
      cout << "The Death Eater defended with its wand!" << endl << endl << "You sustain no damage, while the Death Eater loses 3 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else {
      
      yourrehealth = 45;
      o1rehealth = 23;
      cout << "The Death Eater healed itself!" << endl << endl << "You sustain no damage, while the Death Eater loses 2 damage, due to your sword and its heal. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    
  }
  else if (yourmove == 'm'){
    int onum = rand() % 5 + 1;
    cout << "You attacked with your wand!" << endl;
    if (onum == 1){
      
      yourrehealth = 42;
      o1rehealth = 21;
      cout << "The Death Eater attacked with its sword!" << endl << endl << "You lose 3 damage, while your opponent loses 4 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " ." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 2){
      
      yourrehealth = 41;
      o1rehealth = 21;
      cout << "The Death Eater also attacked with its wand!" << endl << endl << "You each lose 4 damage! You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 3){
      
      yourrehealth = 45;
      o1rehealth = 21;
      cout << "The Death Eater defended with its shield!" << endl << endl << "The wrong defense was used! You stay unharmed, while the Death Eater loses 4 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth - 4 << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 4){
      
      yourrehealth = 42;
      o1rehealth = 25;
      cout << "The Death Eater defended with its wand!" << endl << endl << "You get 3 damage of backlash, while the Death Eater is unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else {
      
      yourrehealth = 45;
      o1rehealth = 22;
      cout << "The Death Eater healed itself!" << endl << endl << "You sustain no damage, while the Death Eater loses 3 damage, due to your wand and its heal. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
  }
  else if (yourmove == 'h'){
    int onum = rand() % 5 + 1;
    cout << "You healed yourself!" << endl;
    if (onum == 1){
      
      yourrehealth = 43;
      o1rehealth = 25;
      cout << "The Death Eater attacked with its sword!" << endl << endl << "You lose 2 damage, while your opponent loses no damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " ." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 2){
      
      yourrehealth = 42;
      o1rehealth = 25;
      cout << "The Death Eater attacked with its wand!" << endl << endl << "You lose 3 damage, while the Death Eater is unharmed! You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 3){
      
      yourrehealth = 46;
      o1rehealth = 25;
      cout << "The Death Eater defended with its shield!" << endl << endl << "You gain 1 health, while the Death Eater is unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth - 4 << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 4){
      
      yourrehealth = 46;
      o1rehealth = 25;
      cout << "The Death Eater defended with its wand!" << endl << endl << "You gain 1 health, while the Death Eater is unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else {
      
      yourrehealth = 46;
      o1rehealth = 26;
      cout << "The Death Eater also healed itself!" << endl << endl << "You both gain 1 health. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
  }
  else if (yourmove == 's'){
    int onum = rand() % 5 + 1;
    cout << "You defended with your shield!" << endl;
    if (onum == 1){
      yourrehealth = 45;
      o1rehealth = 22;
      cout << "The Death Eater attacked with its sword!" << endl << endl << "You defended with your shield, staying unharmed, while your opponent loses 3 damage. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " ." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 2){
      
      yourrehealth = 41;
      o1rehealth = 25;
      cout << "The Death Eater attacked with its wand!" << endl << endl << "You defend incorrectly, losing 4 damage, while the Death Eater is unharmed! You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 3){
      
      yourrehealth = 45;
      o1rehealth = 25;
      cout << "The Death Eater defended with its shield!" << endl << endl << "You both are unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth - 4 << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else if (onum == 4){
      
      yourrehealth = 45;
      o1rehealth = 25;
      cout << "The Death Eater defended with its wand!" << endl << endl << "You both are unharmed. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
    else {
      
      yourrehealth = 45;
      o1rehealth = 26;
      cout << "The Death Eater healed itself!" << endl << endl << "You are unharmed, while the Death Eater gains 1 health. You have " << yourrehealth << " XP and your opponent has " << o1rehealth << " XP." << endl << endl;
      int onum = rand() % 5 + 1;
    }
  }
  
}

void enterdarkcave () {
  cout << "Harry has set off on a mission to destroy Voldemort for good. He learns that Voldemort is hiding deep in a cave. He enters this gloomy cave, and is immediately met by a murderous Death Eater with 25 XP! Prepare to battle!" << endl << endl << endl;
  battle1();
};

void beginning(){
  
   
  
  cin >> start;
  if ((start == 'y') || (start == 'Y')){
    enterdarkcave();
  }
}

int main(){
  
  srand ( time(NULL) );
  beginning();
  system("pause");
  
 }

Last edited on
What limit? C++ source files are not limited in size.
However, you seem to have a lot of code duplication, so you could easily reduce the file size by moving duplicate code into functions.
Last edited on
Well, I was compiling, it gave me an error saying I was using too many bytes, and thanks for the tip too! And another question -- would switches as opposed to if elses use less space?
From when is your compiler? 1980?
In any case, download a recent IDE and compiler:
http://www.codeblocks.org/ or
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express

would switches as opposed to if elses use less space?

Usually, yes.
But seriously, you should be more concerned with your code duplication. You can probably easily reduce your code to a tenth of its size.
Last edited on
Ok, I'll get codeblocks and unduplicate my code. And my compiler is bloodshed dev c++, which I guess is old. Thanks!!
Topic archived. No new replies allowed.