# Thread: some easy help needed

1. ## some easy help needed

Ok, suppose two teams are playing a game against each other, and the winner will advance to the next round. I have to randomly choose one out of two teams chosen, based on their rank out of 16, to advance. How would I do this using RandGen? The team ranked 1 will play 16, rank 2 plays 15, rank 3 plays 14... etc.

and for the rank 1 against rank 16 game, the odds are in rank 1's favor, except there is sitll a chance of rank 16 winning.

thanks a lot for help.

2. [code]

int t1,t2;

t1=random(17);
t1=t1+1;

re:
t2=random(17);
t2=t2+1;
if(t2==t1)
goto re;

if(winner==0)
cout<<"TEAM "<<t1<<" chosen";
if(winner==1)
cout<<"TEAM "<<t2<<" chosen";

[\code]

not tested program/code

random() = stdlib.h

random(17) = randomely selects any num from 0 to 16, that's why i added 1 to t1,t2

if you don't want goto [nobody likes it] use do-while. it's better but goto is simple.

3. this is the code my teacher gave us to look at.
it doesn't go up to the final four or the semifinals.
#include<iostream.h>
#include<fstream.h>
#include"RandGen.cpp"
#include"apvector.h"
#include"apstring.cpp"
#include<stdlib.h>
struct region
{
apstring name;
apvector<apstring>teams;
};
void main()
//East Midwest South West
{
apvector<region>bracket(4);
ifstream infile;
infile.open("bracket.dat",ios::in);
for(int i=0; i<4; i++)
{
bracket[i].teams.resize(17);
getline(infile, bracket[i].name);
for(int j = 1; j <=16; j++ )
{
getline(infile, bracket[i].teams[j]);
}
}
RandGen n;
// games in a region
for( i = 0; i<4; i++ )
{
cout<<bracket[i].name<<" Region\n";
for(int j=1; j<=8; j++)
{
int t = n.RandInt(1,17);
cout<<"Game "<< j << endl;
cout<<bracket[i].teams[j]
<<" vs. "
<<bracket[i].teams[17-j]
<<endl;

cout<<"Winner is ";
if(j < 17 - t)
cout << bracket[i].teams[j] << endl;
else
cout << bracket [i].teams[17-j] << endl;

}
cin.get();// creates a pause between brackets
system("cls");// clear the screen
}

}

//end code

ok i dont get the ........

cout<<"Winner is ";
if(j < 17 - t)
cout << bracket[i].teams[j] << endl;
else
cout << bracket [i].teams[17-j] << endl;

........ part of that