need help with program that prints out random numbers



output should look like this -




so far i have this

[code]#include <iostream>
#include <time.h>
using namespace std;

int main()
{

srand(time(NULL));

int B1 = random()%35 + 1;
int B2 = random()%35 + 1;
int B3 = random()%35 + 1;
int B4 = random()%35 + 1;
int B5 = random()%35 + 1;
while (B2 == B1)
while (B3 == B1 || B3 == B2);
while (B4 == B1 || B4 == B2 || B4 == B3)
while (B5 == B1 || B5 == B4 || B5 == B3 || B5 == B2)

int R = rand()5% + 1;
if (R==1)cout << "Low number\n";
if (R==2)cout << "wowsers\n";
if (R==3)cout << "unbelieveable\n";
if (R==4)cout << " Your a champ\n";
if (R==5)cout << " God is with you\n";

return 0;


i am getting these errors when i compile it

random.cpp: In function âint main()â:
random.cpp:23: error: expected â,â or â;â before numeric constant
random.cpp:24: error: âRâ was not declared in this scope
random.cpp:25: error: âRâ was not declared in this scope
random.cpp:26: error: âRâ was not declared in this scope
random.cpp:27: error: âRâ was not declared in this scope
random.cpp:28: error: âRâ was not declared in this scope



any help would be much apprecaited thank you
Last edited on
i think you forgot the brackets for each of the while loops.

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
34
35
36
37
38
39

#include <time.h>
#include <iostream>
using namespace std;

int main()
{
	int R = 0;
	int B1=0, B2=0, B3=0, B4=0, B5=0;
	srand(time(NULL));
	bool n = true;
	while(n){
		int B1 = rand()%35 + 1;
		int B2 = rand()%35 + 1;
		int B3 = rand()%35 + 1;
		int B4 = rand()%35 + 1;
		int B5 = rand()%35 + 1;
		cout<<"Here is your Texas Two Step quick pick: "<<B1<< " " <<" "<<B2 <<" "<<B3 <<" "<<B4 <<" "<<B5<<endl;
		cout<<"May the balls fall in your favor"<<endl;
		R = rand()%5 + 1;
		cout<<R;
		if (R==1)cout << "Low number\n";
		if (R==2)cout << "wowsers\n";
		if (R==3)cout << "unbelieveable\n";
		if (R==4)cout << " Your a champ\n";
		if (R==5)cout << " God is with you\n";


		cout<<"Would you like to draw again?(1-Yes, 0-No)"<<endl;
		cin >> n;
		
	}
	//while (B2 == B1)
	//while (B3 == B1 || B3 == B2);
	//while (B4 == B1 || B4 == B2 || B4 == B3)
	//while (B5 == B1 || B5 == B4 || B5 == B3 || B5 == B2)
	return 0;
}
Last edited on
You would probably find it easier to use an array of 35ints (1-35) can be done with a simple loop.
1
2
int array[35], limit = 35, temp;
for(int i=0;i<limit<i++){array[i] = i;}

Then randomise a number between 0 and 36, or -1 and 35.
Then you could either get the value of:
array[picked - 1]
or
array[picked]
Depending on which boundaries you set for random.

Then to prevent double number,
1
2
3
temp = array[limit - 1];
array[limit - 1] = array[picked];
array[picked] = temp;

^simple swap, better to have it in a function and pass picked and limit into it.
Then at the end of the for loop
limit--;
thank you guys thats exactly what i was missing !!!

one more question the random good luck statement is suppose to go where it says" May the balls fall in your favor"

how do i rearrange it to randomly insert one of my 5 statements?

thank you again
Topic archived. No new replies allowed.