Im having problems with my if else/ switch statements.

Im having problems with my if else/ switch statements.
Im working on a code that is a math tutoring program, and it has to ask a multiplication problem if the answer is wrong, it needs to ask the question ten times, and if its correct another ten questions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;
#include<conio.h>
#include<stdlib.h>
#include<time.h>

int main ()
{
int numbers[3];
int answer = 0; /* USER INPUT */
srand (time(0)); 


/* Initiate checking for correct answer */ 
while (answer != 1) /* WHILE USER HASN'T ENTERED 1 */
{
numbers[0] = rand() % 9 + 1; /* load the first random number into numbers[0] */
numbers[1] = rand() % 9 + 1; /* load the second into numbers[1] */
numbers[2] = numbers[0] * numbers[1]; /* load the answer into numbers[2] */
cout << "Correctly answer the following or enter 1 to quit" << endl; /* PROMPT */ 
cout << "\n\n""What is " << numbers[0] << "*" << numbers[1] << "?" << endl;
cin >> answer;
if (answer == numbers[0] * numbers[1]) /* check against the numbers array */
{
cout << "\n""Very Good!"<< endl; /* Outcome for correct answer */

}

else /* statement for while loop */
cout << "\nNo, please try again! The correct answer was " << numbers[2] << endl; //Outcome for incorrect answer
}
return 0;
}


I did the actual game part of it asking questions regarding multiplication
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;
#include<conio.h>
#include<stdlib.h>
#include<time.h>

int main ()
{
int numbers[3];
int answer = 0; /* USER INPUT */
srand (time(0)); 


/* Initiate checking for correct answer */ 
while (answer != 1) /* WHILE USER HASN'T ENTERED 1 */
{
numbers[0] = rand() % 9 + 1; /* load the first random number into numbers[0] */
numbers[1] = rand() % 9 + 1; /* load the second into numbers[1] */
numbers[2] = numbers[0] * numbers[1]; /* load the answer into numbers[2] */
cout << "Correctly answer the following or enter 1 to quit" << endl; /* PROMPT */ 
cout << "\n\n""What is " << numbers[0] << "*" << numbers[1] << "?" << endl;
cin >> answer;
if (answer == numbers[0] * numbers[1]) /* check against the numbers array */
{
cout << "\n""Very Good!"<< endl; /* Outcome for correct answer */

}

else /* statement for while loop */
cout << "\nNo, please try again! The correct answer was " << numbers[2] << endl; //Outcome for incorrect answer
}
return 0;
}
Last edited on
closed account (48T7M4Gy)
1. Please use code tags
2. Just pick one of your mains not two
3. I think I understand your problem and I'd suggest you put pen to paper and write down the pseudocode which, if I understand you correctly, goes something like this:

a) there are 10 types of question overall
b) try a particular type of question
c) if the answer to that question is correct go on to the next type
d) otherwise try out the type of question selected in b) up to 10 times ( who knows what happens if you fail 10 times?)
e) ... keep going until 10 types have been successfully completed

You will need a bit more detail and more simple steps whatever the target idea is.



Code tags are what exactly?
What i need to do is make a multiplication program if a person answers it correctly it goes up to ten questions if the user keeps answering the question correctly.
If the person answers it wrong it will show that same question until the person gets it right up to ten times repeating the same question. Has to loop exactly 10 times.
closed account (48T7M4Gy)
Code tags are wrap around tags that put you code into the line-numbered listings you see everywhere here Use the <> tool in the format box on the right hand side.

What i need to do is make a multiplication program if a person answers it correctly it goes up to ten questions if the user keeps answering the question correctly.


That's great so what's the problem with writing a bit of pseudocode by breaking that down to some simple steps and then after that writing the code or amending what u have so far?. You aren't very far off getting it right.
Topic archived. No new replies allowed.