|
-
May 24th, 2010, 01:54 PM
#1
Random number generator
Ok so im helping out my local gaming center by writing a program that allows me to input the number of teams that are participating in a tournament, then output what bracket line they will be on for the brackets tournament. I have everything working except the numbers repeat, I need a way to check and "re-roll" so the numbers never match. I know i can use a for loop but its been almost 4 years since ive written a program. I was also thinking if there is a way i can just fill the array and then shuffle it and print the numbers that way. Any help is appreciated.
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <time.h>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
int x;
cout<<"how many teams are in the tournament?"<<endl;
cin>>x;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
int i;//spot
int t;//team
int spots[x];
i=0;
t=1;
while(i<x)
{
spots[i]=rand()%(x-1+1)+1 ;
cout<<"Team "<<t<<" is on bracket line "<<spots[i];
i=i+1;
t=t+1;
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Its a little sloppy but it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|