Line 2: There is no <rand> header file. The declaration for rand() is in the <cstdlib> header.
Line 11: missing {
You're also missing a call to srand() to seed the random number generator. Without it, you're going to get the same sequence of numbers every time you run your program.
Lines 14,15,17,19: You missing a ; to terminate the statement.
Line 17: while should not be capitalized.
num is not defined.
your main function has no body(Curley Braces), your code is global. If you have more code, please post it. It's always best to post all of your code, or at least as much as possible.
#include<iostream>
#include <chrono>
#include <random>
int main()
{
// obtain a seed from the system clock:
unsigned seed = static_cast<int> (std::chrono::system_clock::now().time_since_epoch().count());
// seeds the random number engine, the mersenne_twister_engine
std::mt19937 generator(seed);
// set a distribution range (1 - 12)
std::uniform_int_distribution<int> distribution(1, 12);
// pick two random numbers
int firstValue = distribution(generator);
int secondValue = distribution(generator);
std::cout << firstValue << "\t" << secondValue << std::endl;
return 0;
}
#include <iostream>
#include <cstdlib>
usingnamespace std;
int first_value;
int second_value;
int user_value;
int main()
{
do;
{
first_value = rand() % 12 + 1;
second_value = rand() % 12 = 1;
while (first_value != num // second_value != num);
cout << "What is " << first_value << " x " << second_value << "?";
return 0;
}
In terms of the random generator, what will I need to do? Do I add a call before the body? If so, or if not, how might I do that? As a final question, how would I define "num" in line 17? With any integer, or?
you need to call ONCE the srand() function before you use the rand() function, seeding the pseudo-random number generator. Otherwise you will get the same series of numbers each time you run the program.
The best way to do the seeding, if you insist on using the C library random generator, is to include the <ctime> header and use the output of the time() C library function as input to the srand() function: srand(time(NULL));.
The C library random generator is not the best method for obtaining random numbers. You might want to look at the C++ <random> library.
Look at the code I posted earlier for an example of using the C++ <random> library.
How, in the generation, can I exclude the previous outputted numbers? Not all, just the previous one before each generation. Per se, it outputs 1 5, the next generation will not have 1 and 5, but the one after can.