kibafan
09-11-2008, 07:06 PM
There's no computer forum so I posted this here. If this is the wrong place then please do not penalize me for it.
I've just started teaching myself about C++ and wrote a program to test my abilities. It compiles fine and runs fine until it gets to the search at which point it completely hoses my CPU. The source code is listed below.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int i1 = 0;
int i2 = 0;
int choice = 1;
int field;
int result;
int dexlength = 0;
char str[2000];
string parameter;
string string1;
string pokedex[600][5];
string results[600][5];
int main() {
cout << "Loading...";
fstream file_op("pokedex.txt",ios::in);
while (!file_op.eof()) {
file_op.getline(str, 2000);
string1.assign(str);
if (string1 != "/") {
pokedex[i1][i2] = string1;
i2++;
}
else {
i1++;
dexlength++;
}
}
cout << "Done!n";
cout << "Welcome to *******'s Pokedex Program.nn";
while (choice != 0) {
result = 0;
i1 = 0;
i2 = 0;
result = 0;
cout << "In which field will you search?nn1. Number(three-digit format ex:001)n2. Namen3. Type(s)n4. Pre-Evolved Formn5. Evolved Formnn";
cin >> choice;
cout << "nnEnter search parameter.nn";
cin >> parameter;
field = choice - 1;
while (i1 < dexlength);
if (pokedex[i1][field] == parameter) {
results[i2][0] = pokedex[i1][0];
results[i2][1] = pokedex[i1][1];
results[i2][2] = pokedex[i1][2];
results[i2][3] = pokedex[i1][3];
results[i2][4] = pokedex[i1][4];
results[i2][5] = pokedex[i1][5];
i2++;
result++;
}
i1++;
}
cout << result << " results found.n";
i1 = 0;
while (i1 < result) {
cout << "Number: " << results[i1][0];
cout << "Name: " << results[i1][1];
cout << "Type: " << results[i1][2];
cout << "Pre-Evolved Form: " << results[i1][3];
cout << "Evolved Form: " << results[i1][4];
i1++;
}
return 0;
}
It's a lot to sift through, but isn't everything in this language? Any help would be appreciated.
I've just started teaching myself about C++ and wrote a program to test my abilities. It compiles fine and runs fine until it gets to the search at which point it completely hoses my CPU. The source code is listed below.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int i1 = 0;
int i2 = 0;
int choice = 1;
int field;
int result;
int dexlength = 0;
char str[2000];
string parameter;
string string1;
string pokedex[600][5];
string results[600][5];
int main() {
cout << "Loading...";
fstream file_op("pokedex.txt",ios::in);
while (!file_op.eof()) {
file_op.getline(str, 2000);
string1.assign(str);
if (string1 != "/") {
pokedex[i1][i2] = string1;
i2++;
}
else {
i1++;
dexlength++;
}
}
cout << "Done!n";
cout << "Welcome to *******'s Pokedex Program.nn";
while (choice != 0) {
result = 0;
i1 = 0;
i2 = 0;
result = 0;
cout << "In which field will you search?nn1. Number(three-digit format ex:001)n2. Namen3. Type(s)n4. Pre-Evolved Formn5. Evolved Formnn";
cin >> choice;
cout << "nnEnter search parameter.nn";
cin >> parameter;
field = choice - 1;
while (i1 < dexlength);
if (pokedex[i1][field] == parameter) {
results[i2][0] = pokedex[i1][0];
results[i2][1] = pokedex[i1][1];
results[i2][2] = pokedex[i1][2];
results[i2][3] = pokedex[i1][3];
results[i2][4] = pokedex[i1][4];
results[i2][5] = pokedex[i1][5];
i2++;
result++;
}
i1++;
}
cout << result << " results found.n";
i1 = 0;
while (i1 < result) {
cout << "Number: " << results[i1][0];
cout << "Name: " << results[i1][1];
cout << "Type: " << results[i1][2];
cout << "Pre-Evolved Form: " << results[i1][3];
cout << "Evolved Form: " << results[i1][4];
i1++;
}
return 0;
}
It's a lot to sift through, but isn't everything in this language? Any help would be appreciated.