This program has been giving me a lot of issues. I'm positive the syntax is correct but the program won't compile. Here's a few sticking points
1) I must have a function I can call at the beginning of the application as well as when the user gets the answer correct
2) I must come up with a loop that causes the program the check to see if the user has given the correct answer. If so it generates a new question and if not it waits until the user gives the correct answer then loops back to the question generator.
// Function Prototypes
int numGen ();
int questSol ();
int questAns ();
int main() {
//int secAnswer = questGen();
//int secSolution = questtGen();
int ans = questAns();
int sol = questSol();
if (ans == sol){
cout << "Very good! \n";
questAns();
} else {
cout << " Incorrect. Please try again. " << endl;
cin >> ans;
if (ans == sol)
questAns();
}
}
////////////////////////////////////////
int numGen () {
srand(time(0));
int one = rand() % 10;
int two = rand() % 10;
return one;
return two;
};
///////////////////////////////////////
int questSol (int one, int two) {
int solution = one * two;
return solution;
}
//////////////////////////////////////
int questAns (int one, int two) {
int answer;
cout << "How much is " << one << " times " << two << "? \n";
cin >> answer;
return answer;
}
If you wont do: using namespace std;
You will have to put std:: before every cout.
Like so: std::cout << "Hello C++" << std::endl;
And the same about cin.
Sorry, I have the proper headers #include <isotream>, using namespace std, etc. My main issue, apparently, is that I have functions a bit confused. My new plan of attack is to create the random numbers in the main function, save their results as variables and then call a function using those two values. Am I on the right track?
Yeah, that sounds like a plan. But you need to read up a bit on functions.
OPne thing I noticed is you can't really say return solution;
I think I know what you mean but it's not C++ because unless you declare an integer variable called solution (or one, two as you've done elsewhere nothing will happen except error messages.
ok I'm still running into the same basic problem. What the code listed below should do, from my point of view, is generate two random numbers and then pass them along to the function I've called. Same error and I'm still confused. I've read the function tutorial but...I'm still missing something
The prototype and the implementation parameter list must match exactly. When you call the function the parameters have to match.
int questGen (int, int);
questGen(one, two);
int questGen() - doesn't %$@! match - STUDY the tutorial otherwise you'll just go through the same cycle of making the same mistake whereupon people will rapidly lose interest.