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
|
#include <iostream>
#include <string>
using namespace std;
int newInning(char,int, int, int, int, int, int);
int main()
{
char code, inning, atBat='V';;
int ball=0, bat=1, out=0, strike=0, hs=1, vs=1, cnt=1, run=0;
//menu
cout<<"Delayed Spring Training 2014\nUmpire's Assistant At Your Service\n\n";
cout<<"\n\nThe menu is: "<<endl;
cout<<"\n Item \t Code Description \t Item\t Code Description"<<endl;
cout<<" R\tRun Scored \t \t O\tOut"<<endl;
cout<<" F\tFoul Ball \t \t S\tStrike"<<endl;
cout<<" B\tBall\t\t\t H\tHit"<<endl;
cout<<" G\tGame Canceled"<<endl<<endl;
cout<<"\n********** Visitor team is at bat Home team is in the field**********\n\n";
do
{
cout<<"Inning Status\tBatter # "<<bat<<"\t # Balls "<<ball;
cout<<" # Strike "<<strike<<" # Outs "<<out<<" # Runs "<<run<<endl;
cout<<bat<<" Batter (count of "<<cnt<<"): ";
cin>>code;
switch (toupper(code))
{
case 'S':"Strike";
if (strike<2)
{++strike;
++cnt;}
else if (strike==2)
{
strike=0;
ball=0;
cnt=1;
out++;
++bat;
if (out==3)
newInning(atBat,out,strike,ball,cnt,run,bat);
}
break;
case 'B':"Ball";
if (ball<3)
{ ++ball;
++cnt;}
else if (ball==3)
{
ball=0;
strike=0;
cnt=1;
++bat;
}
break;
case 'F':"Foul Ball";
cnt++;
if (strike<2)
strike++;
break;
case 'G':"Game Canceled";
return 0;
break;
case 'H':"Hit";
bat++;
ball=0;
strike=0;
cnt=1;
break;
case 'O':"Out";
if (out<2)
{
++out;
++bat;
}
else if (out==2)
{
cout<<"\n\t\t\t\t\Three Outs!!!\n\n\n";
newInning(atBat,out,strike,ball,cnt,run,bat);
}
break;
case 'R': "Run In";
run++;
default: cout<<"\n\n**********Invalid selection. Please enter S, B, F, G, H, O, or R**********\n\n";
}
}
while (inning!='n' || inning!='N');
cin.get();
cin.get();
return 0;
}
int newInning(char,int, int, int, int, int, int)
{
char inning, atBat;
int ball=0, bat=1, out=0, strike=0, hs=1, vs=1, cnt=1, run=0;
cout<<"Is there another half Inning (Y/N)? ";
cin>>inning;
if (inning=='n' ||inning=='N')
return 0;
if(atBat=='H')
{
atBat='V';
cout<<"\n**********Visitor team is at bat Home team is in the field**********\n\n";
out=0;
strike=0;
ball=0;
cnt=1;
run=0;
bat=1;
}
else if (atBat=='V')
{
atBat='H';
cout<<"\n**********Home team is at bat Visitor team is in the field**********\n\n";
out=0;
strike=0;
ball=0;
cnt=1;
run=0;
bat=1;
}
return inning;
}
|