Here's my code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
string substring(string a, int b, int c) {
string result = "";
for (int i = b; i < b + c; i++) {
result += a[i];
}
return result;
}
int main() {
ifstream in_stream;
in_stream.open("HW3Test.txt");
ofstream output_stream("HW3output.txt");
string result[100];
int i = 0;
while (in_stream >> result[i]) {
i++;
}
string check[i];
for (int k = 0; k < i; k++) {
check[k] = substring(result[k], 0, 2);
}
string scores[i];
for (int k = 0; k < i; k++) {
if (check[k][0] >= '0' && check[k][0] <= '9') {
scores[k] = check[k];
}
}
for (int k = i; k >= 0; k--) {
output_stream << scores[k] << endl;
}
for (int k = 0; k < i; k++) {
if (!(result[k][0] >= '0') && !(result[k][0] <= '9')) {
output_stream << result[k];
}
}
}
In this problem, I'm given this input:
86 Bill Fun
93 Kelly Jelly
74 Bob Squee
81 Jim Flim
72 John Fraggle
87 June Prune
63 Roberta Robertson
and trying to achieve this output:
Fun, Bill: 63
Jelly, Kelly: 87
Squee, Bob: 72
Flim, Jim: 81
Fraggle, John: 74
Prune, June: 93
Robertson, Roberta: 86
So, I first got the scores in from the text file, and stored it in a scores array. Now, I need to get only the names, but for some reason, the program is not outputting any text when I check if the first character in the string is not a number. How can I get it to print out only the strings that start with a letter?