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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int scores[11] = { 0 }, balls[11] = { 0 }, extras;
void input(string [][12], int);
int sum(int[]);
int pickteam();
int opponent_team;
extern string team[5][12];
void print_scoreboard(int);
void print_strip(int, int);
string get_short_name(int);
int main()
{
int picked_team = pickteam();
input(team, picked_team);
system("cls");
print_scoreboard(picked_team);
return 0;
}
int pickteam()
{
cout << endl;
cout << "Pick your Team" << endl << endl
<< "1) Pakistan" << endl
<< "2) Australia" << endl
<< "3) England" << endl
<< "4) India" << endl
<< "5) New Zealand" << endl << endl
<< "Your choice: ";
int choice;
cin >> choice;
while (choice < 1 || choice > 5)
{
cout << "Invalid pick. Please enter again: ";
cin >> choice;
}
system("cls");
cout << endl;
cout << "Pick Opponent Team" << endl << endl
<< "1) Pakistan" << endl
<< "2) Australia" << endl
<< "3) England" << endl
<< "4) India" << endl
<< "5) New Zealand" << endl << endl
<< "Your choice: ";
cin >> opponent_team;
while (opponent_team < 1 || opponent_team > 5)
{
cout << "Invalid pick. Please enter again: ";
cin >> opponent_team;
}
return (choice - 1);
}
void input(string team[][12], int picked_team)
{
system("cls");
cout << endl << endl;
for (int i = 0; i < 11; i++)
{
print_strip(picked_team, i);
cout << endl << endl;
cout << team[picked_team][i] << " is batting.\nEnter his score: ";
cin >> scores[i];
while (cin.fail())
{
cout << "Invalid score, please enter again: ";
cin.clear();
cin.ignore();
cin >> scores[i];
}
cout << "Enter the Balls faced by " << team[picked_team][i] << ": ";
cin >> balls[i];
while (cin.fail())
{
cout << "Invalid balls, please enter again: ";
cin.clear();
cin.ignore();
cin >> balls[i];
}
}
cout << "Extras: ";
cin >> extras;
while (cin.fail())
{
cout << "Invalid score, please enter again: ";
cin.clear();
cin.ignore();
cin >> extras;
}
}
void print_strip(int picked_team, int wickets)
{
for (int i = 1; i <= 90; i++)
cout << "-";
cout << endl;
cout << left << setw(10) << get_short_name(picked_team) << " vs " << get_short_name(opponent_team);
cout << left << setw(40) << team[picked_team][wickets] << " 0*";
cout << right << setw(40) << "Overs: " << (int)(sum(balls) / 6) << "." << (int)(sum(balls) % 6) << endl;
cout << left << setw(10) << get_short_name(picked_team) << " " << (int)(sum(scores) + extras) << "-" << wickets;
cout << left << setw(40);
if (wickets == 0)
cout << team[picked_team][wickets + 1] << " 0";
else
cout << team[picked_team][wickets - 1] << " " << scores[wickets - 1];
srand(time(0));
int bowler = rand() % 5 + 7;
cout << right << setw(40) << "Bowler: " << team[opponent_team][bowler] << endl;
for (int i = 1; i <= 90; i++)
cout << "-";
cout << endl;
}
string get_short_name(int team)
{
string Pakistan = "PAK", India = "IND", Australia = "AUS", New_Zealand = "NZD", England = "ENG";
switch (team)
{
case 0:
return Pakistan;
case 1:
return Australia;
case 2:
return England;
case 3:
return India;
case 4:
return New_Zealand;
}
}
int sum(int values[])
{
int res = 0;
for (int i = 0; i < 11; i++)
{
if (values[i] != 0)
res = res + values[i];
}
return res;
}
void print_scoreboard(int picked_team)
{
cout << endl << " " << left << setw(45) << team[picked_team][11] << left << setw(15) << "Runs" << left << setw(15) << "Balls" << endl << endl;
for (int i = 0; i < 11; i++)
{
cout << " " << left << setw(45) << team[picked_team][i] << left << setw(15) << scores[i] << left << setw(15) << balls[i] << endl << endl;
}
cout << right << setw(45) << "Extras " << " " << left << setw(15) << extras << endl << endl;
cout << " Overs: " << (int)(sum(balls) / 6) << "." << (int)(sum(balls) % 6)
<< right << setw(30) << "Total: " << (int)(sum(scores) + extras)
<< right << setw(20) << "Run Rate: " << setprecision(2) << (int)(sum(scores) + extras) / (float)(sum(balls) / 6);
cout << endl << endl << "Press Enter to continue...";
getchar();
getchar();
}
string team[5][12] = { {"Imam ul Haq", "Fakhar Zaman", "Babar Azam", "Muhammad Hafeez", "Haris Sohail", "Sarfraz Ahmed", "Imad Wasim", "Shadab Khan", "Wahab Riaz", "Muhammad Amir", "Shaheen Afridi", "Pakistan" },
{"Aaron Finch", "David Warner", "Usman Khawaja", "Glenn Maxwell", "MP Stoinis", "AT Carey", "Pat Cummins", "Mitchell Starc", "Nathan Lyon", "JP Behrendorf", "Australia"},
{"Jame Vince", "JM Baistow", "Joe Root", "Eion Morgan", "Ben Stokes", "Joe Buttler", "CR Woakes", "Moeen Ali", "Adil Rashid", "JC Archer", "MA Wood", "England"},
{"Rohit Sharma", "Shikhar Dhawan", "Virat Kohli", "K. L. Rahul", "Vijay Shankar", "MS Dhoni", "Kedar Jadhav", "Hardik Pandya", "Muhammad Shami", "Jasprit Bumrah", "Bhuveneshwar Kumar", "India"},
{"Martin Guptill", "Colin Munro", "Kane Williamson", "Ross Taylor", "Tom Latham", "James Neesham", "Colin de Grandhomme", "Mitchell Santner", "Matt Henry", "Lockie Ferguson", "Trent Boult", "New Zealand"} };
|