Hello MarbleHornets,
Thank you for including the ".txt" file. Very helpful.
Things that I have noticed so far.
1. You are missing the header file "<ctime>" for the use of "time" in "srand".
2. "srand" only needs to be called once and should be done at the beginning of main not at the beginning of the function. The way you have it could give you a responce that you do not want based on the seed producing the same random number two or more times. I once read that if you are using Windows that "srand" should be followed by a call to "rand" so that you are not using the very first number.
3.
const int MAX_File =1000;
is misleading. The name "MAXSIZE" or "MAX_SIZE" is a better term. "MAX_File" leads on to believe that it deals with files not an array.
4. In main in the do/while loop before the "cin" you could use a prompt asking
"Enter response" or something like that and after the "cin" the program could use a new line printed to the screen to make the output easier to read. And there are other places in the program that could use a blank line in the output to break it up and make it easier to read.
5. Call it a personal preference, but I like to put a menu in its own function where I can print the menu and verift/validate the input before returning the choice to where it was called from.
6. The "switch" looks good. I did not find any problems with that.
7. The "ReadinResponses" function appeared to work well. I did not find any problem with it.
8. The "magicEightballGame" function appeared to work well.
9. The "printResponse" function. What I noticed there is that the sort routine, which appeared to work properly, should be in its own function so it can be used from more than one place.
9A. The second for loop has a comment "// prints out random response". This is misleading because the loop prints the entire part of the array hat is used not a random response.
10. I did not try the "createResponsefile" function yet. I looks OK, but after entering something new you might want to sort the array.
Once I added the header file "<ctime>" the program seemed to work the way it should. I did not find any of the problems you mentioned.
I did find a problem with this bit of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
if (last!=0)
{for (maxElement = last - 1; maxElement > 0; maxElement--) // sorts strut
{
for (index = 0; index < maxElement; index++)
{
if (organize[index].responses > organize[index + 1].responses)
{
swap(organize[index].responses, organize[index + 1].responses);
swap(organize[index].mood, organize[index + 1].mood);
}//if
}//for
}//for
for(int index=0; index <last; index++)
{
std::cout << organize[index].responses << '\n'; // prints out random response
std::cout << organize[index].mood << '\n'; // prints out random response
}}
else cout << "No input please read an input file using option a\n";
|
The indentation and placement of the closing brace } make it hard to read. When I put your code in my IDE it gave me this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
if (last != 0)
{
for (maxElement = last - 1; maxElement > 0; maxElement--) // sorts strut
{
for (index = 0; index < maxElement; index++)
{
if (organize[index].responses > organize[index + 1].responses)
{
swap(organize[index].responses, organize[index + 1].responses);
swap(organize[index].mood, organize[index + 1].mood);
}//if
}//for
}//for
for (int index = 0; index <last; index++)
{
std::cout << organize[index].responses << '\n'; // prints out random response
std::cout << organize[index].mood << '\n'; // prints out random response
}
}
else cout << "No input please read an input file using option a\n";
|
As you can see the second code is easier to read.
The comments after your closing braces are good, but could be a little more descriptive like: "// End inner for" and " "// End outer for". This just helps to understand what they belong to along with the {} lining up in the same column.
If yo are still having problems be more precise as to what and where you believe the problem to be so I know where to look.
Hope that helps,
Andy