【发布时间】:2015-10-02 14:43:38
【问题描述】:
我需要帮助来确定获胜条件并随机安排球队相互对抗...我随机选择球队参加比赛,我不断让相同的球队参加两次比赛或自己比赛,然后不知道该怎么办
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <sstream>
using namespace std;
struct teams{//declaring a struct for the teams
string side;
int number;
int number1;
}teams1[16], points[16];
//void intro screen(){//function for the introduction screen
void fileData(){//function for reading the teams data file
ifstream input;
input.open("FootballTeam.txt",ios::in); //associate file
if(input.is_open()){//opening the file
for(int x=0; x<16; x++){//looping through the file
input>>teams1[x].side;//getting info from the file
cout<<teams1[x].side<<endl;//printing out the data from the file
}//end for
}//end if
}//end void
void play(){//function for playing the game
srand(time(NULL));
for(int x=0; x<=1; x++){//loop for random teams to play
for(int s=0; s<=7; s++){//loop for randoms goals value
x=rand() %16+1;//randomly selecting two teams
points[s].number=rand()%4+1;//randomly selecting goals
points[s].number1=rand()%7+3;//randomly selecting goals
cout<<teams1[x].side<<" :"<<points[s].number<<" vs "
<<teams1[s].side<<" :"<<points[s].number1<<endl<<endl;//printing out the teams and goals
//cout<<teams1<<" Won this match"<<endl;
}//end for
}//end for
}//end void
int main (){
cout<<"ROUND OF 16 Finalists!!!\n"<<endl;
fileData();
cout<<"\n";
system("PAUSE");
system("CLS");
play();
return 0;
}//end main
【问题讨论】:
-
谢谢你帮了大忙
标签: c++ simulation