So i want to create a function that generates 2 random numbers and adds them together. And also return more than one value(as in return the number generated and the answer).
Soo my returned numbers generated isn't between my defined limits and the returned sum is always equal to zero. Help pls
# include <iostream> // using the iostream header file
# include <ctime> // using the ctime header file to help start the random number generator
# include <cstdlib> // using the cstdlib header file
# include <string>
using namespace std; // use the namespace library in order to use cout, cin etc
static const string correct[] = {
"Very good",
"Exellent",
"Nice work",
"Keep up the good work!"};
question numbergenerator(){
int ans = 0, i, rand_1[2]; // variable declaration and assignment
srand( time(0)); // rand will be triggered by time to generate numbers
for (i = 0; i < 2; i++){ // loop with conditions
rand_1[i] = rand()%9+0; // generates random numbers from 0 to 9
ans += rand_1[i]; // adds together the generated number and assign to ans
}
return question{rand_1[i], ans};
vector<int> yourfunc() //function that returns more than 1 integer, in a vector
{
vector<int> ret;
ret.pushback(rand()%9); //insert random numbers
ret.pushback(rand()%9);
ret.pushback(ret[0]+ret[1]); //insert sum
return ret;
}