0% found this document useful (0 votes)
9 views

C++ Program

C++ Program Questions

Uploaded by

Faisal Amin
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
9 views

C++ Program

C++ Program Questions

Uploaded by

Faisal Amin
Copyright
© © All Rights Reserved
You are on page 1/ 1

Problem: Simple T20 program

Md. Minhaz Akram, EEE 1109

Question: Write a program where user will give the number of teams for T20 Tournament. The valid number will be 2-10.
Each team will play with others 2 times. One is home and another is away match. The result of the match will be based on
tossing coin. This is a basic version of programming; hence simulating real cricket game is not necessary. Use two
functions:
void play(int [],int,int) which will take the array and the index of two team. Based on coin toss value of the
team will be incremented.
void showScore(int [],int) which will display the result of all team.

After playing the entire tournament, the result of all the teams will be shown. Sample output is given below:

enter the number of teams [2-10] :4

Team Played Won


Team1 6 3
Team2 6 2
Team3 6 3
Team4 6 4

#include<iostream> void play(int t[],int i,int j)


#include <ctime> {
#include <cstdlib> for(int k=1; k<=2; k++)
using namespace std; {
int r= rand()%2;
void play(int [],int,int); if(r==1)
void showScore(int [],int); {
t[i]++;
int main() }
{ else
srand(time(0)); {
int n, t[10]= {0}; t[j]++;
do }
{ }
cout <<"enter the number }
of teams [2-10] :"; void showScore(int t[],int n)
cin >> n; {
} cout <<endl <<"Team"<< "\t" <<
while(n<2 || n> 10); "Played"<< "\t"<<"Won"<<endl;
int pl= 2*(n-1);
for(int i=0;i<n;i++)
for(int i=0; i< n-1; i++) {
{ cout <<"Team"<< i+1 <<
for(int j=i+1; j<n; j++) "\t" << pl<< "\t"<<t[i]<<endl;
{ }
play(t,i,j); }
}
}
showScore(t,n);
return 0;
}

You might also like