how to generate 3 random numbers between 1 and 6 using a function called generate_rand

im trying to generate 3 random numbers between 1 and 6 using a function called generate_rand..
but everytime im having an error :
no oprators "<<" matches these operands
and
the last error was :end of file found before the left brace

my program is the following :

# include<iostream>
#include<cstdlib>
using namespace std;

void generate_rand(int&,int&,int&);
int main()
{
int a,b,c;
cout<<generate_rand(a,b,c);
}
void generate_rand(int&x,int&y,int&z)
{
x=1+rand()%6;
do{
y=1+rand()%6;
}
while (y==x);
do{
z=1+rand()%6;
while(z==x ||z==y);
}
Last edited on
There was a space between # and include, so the Operand error was due to the include not actually happening. End of file issue is self explanetory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<cstdlib>
using namespace std;

void generate_rand(int&,int&,int&);
int main()
{
int a,b,c;
cout<<generate_rand(a,b,c);
}
void generate_rand(int&x,int&y,int&z)
{
x=1+rand()%6;
do{
y=1+rand()%6;
}
while (y==x);
do{
z=1+rand()%6;
while(z==x ||z==y);
}
Last edited on

thanks for the reply
but no its not the solution i tired it now and its still not working
void generate_rand(int&,int&,int&);
returns a void and you are trying to cout it.

cout<<generate_rand(a,b,c);

instead you need to output a, b and c.
Last edited on
ok i put it alone and then i did cout<<a,b,c
but still not working : error end of file found before the left brace

#include<iostream>
#include<cstdlib>
using namespace std;

void generate_rand(int&,int&,int&);
int main()
{
int a,b,c;
generate_rand(a,b,c);
cout<<a,b,c;
}
void generate_rand(int&x,int&y,int&z)
{
x=1+rand()%6;
do{
y=1+rand()%6;
}
while (y==x);
do{
z=1+rand()%6;
while(z==x ||z==y);
}

1
2
3
4
5
  do{
    z=1+rand()%6;
  }while(z==x ||z==y);

} 


You need to close the do...while loop
thank you problem solved
Topic archived. No new replies allowed.