The first thing to do would be to make proper indentation so your code can actually be read.
I am such a nice guy that I did it for you, and added comments for you to read.
C++:
void PhraseGen::output(string inputPhrase[], string inputDef[], int terms)
{
int index, counter = 0;
string phrase;
string restart, yesOrNo;
do
{
// This whole block should be in a function, since you want to run it again if the user answers "Yes" later on
do
{
srand(time(NULL)); // You don't need to keep feeding the RNG with a new seed, do it once at the start of the program
index = rand() % terms;
cout << "What is: " << inputPhrase[index] << "? ";
cin >> phrase;
cout << endl; // Don't use endl all over the place
if (inputDef[index] == phrase)
{
cout << "You're correct!" << endl << endl; // Don't use endl all over the place
}
else
{
cout << "That's wrong try again" << endl << endl; // Don't use endl all over the place
counter++; // You are incrementing counter, but never set it back to 0 (which didn't effect you because you are not actually using this block twice). Set it to 0 before this loop.
if (counter >= 5)
{
cout << endl << endl << "You seem to be having a hard time with this question. Try studying more and" << endl << "then coming back to test yourself" << endl << endl; // Don't use endl all over the place
}
}
} while (inputDef[index] != phrase);
cout << "Would you like to pick a new phrase? (Yes/No): ";
cin >> yesOrNo;
cout << yesOrNo;
if (yesOrNo == "No" || "N" || "n" || "no") // "N", "n" and "no" are string objects and are evaluated to "true", so this condition is alwasy true
{
(true); // What exactly is this supposed to do?? This is just an expression that evaluates to "true"
}
// This can be else if
if (yesOrNo == "Yes" || "yes" || "y" || "Y") // "yes", "y" and "Y" are string objects and are evaluated to "true", so this condition is alwasy true
{
// This breaks from the main loop, isn't this supposed to be in the "No" option?
break;
}
} while (true);
}
If you keep feeding the RNG with a new seed, it's not much of an RNG. Seed it once when the program starts, and then let it do its job by calling rand().
In general, try to surround blocks with the block characters {}, even when they have only one expression. You will avoid many arbitrary bugs and debugging in the future if you do.
Don't use std::endl without actually knowing what it does (apart from making a new line).
Unless you know that you specifically need std::endl, simply use the escape character \n.
When writing multiple expressions in a condition, remember that each one is evaluated on its own.
Having the condition
if (a == 1 || 2)
may look like it checks if a is equal to 1 or 2, but it in fact checks if the expression a==1 is true, and if a==1 is false then it goes on to check if the expression 2 is true, which always evaluates to true (since 2 evaluates to true in boolean expressions).
As general feedback:
Your code doesn't handle the case when a phrase was already selected and beaten (matched correctly), you might want to add that, by keeping track of all the matched phrases and rand() until you get something that wasn't matched (you could use std::map for this).
I don't know what sort of phrases you have, but you should do case-insensitive checks on the strings (
here's an example on how to easily do that).