random numbers??

hello guys,

for example i have three numbers which are (2,4,6), and I want to print these numbers randomly

please reply in code

waiting for you
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
#include <iostream>
#include <time.h>

using namespace std;

int main()
{
	int a;
	cout << "Please do my homework for me\n\n hit any key then enter to contiinue\n";
	cin >> a;
	a=1;
	srand(time(NULL));
do 	{
		int homework = rand() %3+1;
		if (homework ==1) cout << "Do your own damn homework!\n";
		else if (homework ==2) cout << "Write some of your own code and we will advise\n";
		else if (homework ==3){ cout << "http://www.cplusplus.com/reference/clibrary/cstdlib/rand/\n";
		cout << "http://www.cplusplus.com/reference/clibrary/cstdlib/srand/\n\n";}
		a+=1;
	} while(a<=20);




	return 0;

}




In code just like you asked :)
Why did you do
a+=1

isn't it the same to do
a++
ok could you please see my code


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
srand(time(NULL));
    system("MODE CON: COLS=90 LINES=360");
    system("TITLE Press ^<ESC^> to exit");
    cout <<      "Press <ESC> to exit\n\n";
    int   milliseconds = 500;
    char  key=0, esc=27;
    while(key != esc)
    {
	
     int villain = rand();
     system("cls");
   
       char wall = 177, flute = 14, hero = 2,
        life_hero = 3,life_evil = 3,villain1=1, bomb = 15,
        fish = 21;
         keys();       
         cout <<"                   +------------------+                          "<<endl;
         cout <<"                   |                  |                          "<<endl;
         cout <<"                   |         "<<fish<<"        |                          "<<endl;            
         cout <<"                   |                  |                          "<<endl;
         cout <<"                   |                  |                          "<<endl;
         cout <<"  +----------------+--------   -------+---------------+     "<<endl;
         cout <<"  |                         "<<life_evil<<""<<life_evil<<""<<life_evil<<"                       |     "<<endl;
         cout <<"  |                         "<<villain<<" "<<villain<<"                       |     "<<endl;
         cout <<"  |                          "<<hero<<"                        |     "<<endl;
         cout <<"  |                         "<<life_hero<<""<<life_hero<<""<<life_hero<<"                       |     "<<endl;
         cout <<"  +----------------+--------   -----+-----------------+     "<<endl;
         cout <<"  |                |                |                 |     "<<endl;
         cout <<"  |                |                |                 |     "<<endl;
         cout <<"  |                                                   |     "<<endl;
         cout <<"  |                |                |                 |     "<<endl;
         cout <<"  |                |                |                 |     "<<endl;
         cout <<"  +----------------+----------------+-----------------+     "<<endl; 




please compiler this code to test it

now can you see the 'vallian' varible?

every time i want the villaian to move right,middle,left randomly

please help

waiing for you
please help
Not sure what you want to do... is it that instead of finding a random number in a range, e.g. 1-100, you want to have a random number from only 2 , 4, or 6 ?

I would add them to an array, then find a random number from 0-2, and do it that way.
Topic archived. No new replies allowed.