• 0

C++ Program


Question

I need help on making a program where the program will ask the user a number of random maths questions, for example 4*4 =

the program will only ask another question if there is a correct answer for the previous question.

Please Help

Richard

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

do the questions have to be different every time? (actually random?)

an easy way to do it would be with a large switch statement.

Have a random # generated and then mod it by however many questions you have.

Make this number go to a specific case (the same #) in the switch statement. Each switch statement will have a question with an answer tested.

If it is right then it will go back to a random #, if it gets it wrong it will end.

pretty basic

Link to comment
Share on other sites

  • 0

A simpler way, IMO, would be:

#include <iostream>

#include <***.h> // *** is the lib where razdomize(), random () are defined

int main ()

{

randomize();

while (1)

{

make a question();

cout<<question;

cin>>user_ans;

if (user_ans!=correct_ans)

break;

// else another iteration of the while loop

}

return 0;

}

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.