Calculator help

I am stuck in this giant mess that is originally intended to be a calculator for a paper-based strategic game. I've been trying to do a mechanism where a set of data can be loaded into the program and memorized for later use, but I have no idea how.

The method I am attempting is located in the "load" function, and it consists of the usage of arrays/strings to define the various stats that will be used later on. I am currently stuck on the part where a string to char conversion is made. If someone could devise a better solution for this it would be much appreciated. (I'm suspecting that it has something to do with memory)

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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <complex>
#include <string>
#include <set>
using namespace std;

void Help();
int Battle();
int Nation();
int Map();
void Ver();
int Load(string &Army1, string &Army2, string &Army3, string &Army4, string &Army5, string &Army6, string &Army7, string &Army8, string &Army9, string &Army10);

class Nation
{
public:
	string Name;
	string Serial;
	//General Stats
	int Period;
	int Ideology;
	int PlayerName;
	int National_Morale;
	int Population;
	int Economy;
	int Treasury;
	//Core Tech Stats
	int Mathematics;
	int Physics;
	int Chemistry;
	int Biology;
	int Society;
	//Tech stats
	int Logic;
	int Statistics;
	int Energy;
	int Astronomy;
	int Resources;
	int Materials;
	int Genetics;
	int Nature;
	int Culture;
	int Diplomacy;
	int Information;
	int Medicine;
	int Agriculture;
	int Engineering;
	//Resource stats
	int Natural_Radioactive_Materials;
	int Rare_Earth_Metals;
	int Minerals;
	int Arable_Land;
	int Energetic_Material_and_Fuel;
	int Marine_Resources;
	int Bio_Material;
	int Strategic_Resources;
};

class Army
{
public:
	string Commander;
	string Serial;
	int Stance;
	int ArmyType;
	int Movement_Speed;
	int Offense;
	int Defense;
	int Strength;
	int Movement_Point;
	int Unit_Morale;
	int Unit_Count;
	int Unit_Type;
};

class Support
{
public:
	string Name;
	string Serial;
	int Firepower;
	int Type;
	int Accuracy;
};

class Commander
{
public:
	string Name;
	string Serial;
	int Loyalty;
	int Land_Ability;
	int Air_Ability;
	int Naval_Ability;
	int Potential;
	int Rank;
};

int main()
{
	int CurrentSeason = 1;
	int Active = 1;

	//ArmyLoad
	string Army1 = "Empty Slot";
	string Army2 = "Empty Slot";
	string Army3 = "Empty Slot";
	string Army4 = "Empty Slot";
	string Army5 = "Empty Slot";
	string Army6 = "Empty Slot";
	string Army7 = "Empty Slot";
	string Army8 = "Empty Slot";
	string Army9 = "Empty Slot";
	string Army10 = "Empty Slot";

	//NationLoad

	//MapLoad

	cout << "Welcome to the simulation, what is your request? (Enter [help] to see available commands.)" << endl;

	while (Active == 1)
	{
		string Command;
		cin >> Command;

		if (Command == "help")
		{
			Help();
		}

		else if (Command == "battle")
		{
			Battle();
		}

		else if (Command == "nation")
		{
			Nation();
		}

		else if (Command == "map")
		{
			Map();
		}

		else if (Command == "load")
		{
			Load(Army1, Army2, Army3, Army4, Army5, Army6, Army7, Army8, Army9, Army10);
		}

		else if (Command == "version")
		{
			Ver();
		}
	}

	return 0;
}

void Help()
{
	cout << "This is a list of executable commands that can be entered into the program:" << endl;
	cout << "" << endl;
	cout << "To initiate a battle simulation: [battle]" << endl;
	cout << "To initiate a economic simulation: [nation]" << endl;
	cout << "To initiate a map-based simulation: [map]" << endl;
	cout << "To create or load a nation or an army: [load]" << endl;
	cout << "To check the version of this product: [version]" << endl;
}

int Battle()
{
	char ArmyName;
	char SupportName1;
	char SupportName2;
	char SupportName3;
	char SupportName4;

	cout << "Please select army:" << endl;
	cin >> ArmyName;

	cout << "Please enter the name of the first support army: (enter [0] if none)" << endl;
	cin >> SupportName1;

	cout << "Please enter the name of the second support army: (enter [0] if none)" << endl;
	cin >> SupportName2;

	cout << "Please enter the name of the third support army: (enter [0] if none)" << endl;
	cin >> SupportName3;

	cout << "Please enter the name of the fourth support army: (enter [0] if none)" << endl;
	cin >> SupportName4;

	return 0;
}

int Nation()
{
	return 0;
}

int Map()
{
	return 0;
}

void Ver()
{
	cout << "The current version is 1.0." << endl;
}

int Load(string &Army1, string &Army2, string &Army3, string &Army4, string &Army5, string &Army6, string &Army7, string &Army8, string &Army9, string &Army10)
{
	cout << "Armies:" << endl;
	cout << Army1 << endl;
	cout << Army2 << endl;
	cout << Army3 << endl;
	cout << Army4 << endl;
	cout << Army5 << endl;
	cout << Army6 << endl;
	cout << Army7 << endl;
	cout << Army8 << endl;
	cout << Army9 << endl;
	cout << Army10 << endl;
	cout << "" << endl;
	cout << "Nations:" << endl;
	cout << "-" << endl;
	cout << "" << endl;
	cout << "Nations:" << endl;
	cout << "-" << endl;
	cout << "" << endl;

	string ObjectChoice;
	cout << "Do you want to create an object or load one? (enter [create] or [load])" << endl;
	cin >> ObjectChoice;

	if (ObjectChoice == "create")
	{
		cout << "What object do you want to create?" << endl;
		int TypeChoice;
		cin >> TypeChoice;
	}

	if (ObjectChoice == "load")
	{
		cout << "Please enter the associated statistics serial of the object:" << endl;
		
	    string InputS;
		cin >> InputS;
		
		cout << "Which slot do you want to save it in? (enter an interger from 1 to 10)" << endl;
		int SlotNum;
		cin >> SlotNum;
		
		if (SlotNum <= 10 || SlotNum >= 1)
		{
			cout << "Value valid, processing..." << endl;
			if (InputS[1] == 'A')
			{
				cout << "Army has been loaded" << endl;
				Army1 = 1;
			}
			if (InputS[1] == 'N')
			{
				cout << "Nation had been loaded" << endl;
			}
		}

		else
		{
			cout << "Invalid input" << endl;
			cin >> SlotNum;
		}
	}
	return 0;
}
Last edited on
Have a closer look at your if statement on line 258.
What will happen if SlotNum is >=12 or <= 0
Are you aware the the first index of a string is 0? (lines 261 and 266)
Topic archived. No new replies allowed.