#include <iostream>
#include <ctime>
#include <cstdlib>
/*This program is a game where the computer picks a random number and the user has 3 tries to get a run by guessing the
randomized number between 1-10.
There are 5 innings, each time the user guesses correctly, they score 1 run, the program proceeds to the next inning until
the complete the 9th inning.*/
usingnamespace std;
int baseball();
int main()
{
int swing;
int tries = 0;
int run = 0;
int innings = baseball();
int totalInnings = 6;
srand(time(NULL));
int number = rand() % 10 + 1;
while (innings != totalInnings)
{
for (tries = 1; tries < 4; tries++)
{
cout << "Enter a number between 1 and 10: ";
cin >> swing;
cout << endl;
if (!(swing >= 1 || swing <=10))
{
cout << "Illegal Swing, due to inablility to follow simple instructions,\nthis is counted as a Strike." << endl;
}
/*if (swing == 0 || swing > 10)
{
cout << "Illegal Swing, due to inablility to follow simple instructions,\nthis is counted as a Strike." << endl;
}*/
if (tries == 1 && swing != number)
{
cout << "Strike 1!" << endl;
cout << endl;
}
elseif (tries == 2 && swing != number)
{
cout << "Strike 2!" << endl;
cout << endl;
}
elseif (tries == 3 && swing != number)
{
cout << "Strike 3! You're outta here! \nNo Runs scored!" << endl;
if (innings < 3)
cout << "\nINNING COMPLETE.\n\n";
innings++;
//break;
}
if (swing == number)
{
cout << "Home Run! Congratulations." << endl;
if (innings < (totalInnings - 1))
cout << "\nINNING COMPLETE.\n\n";
run++;
innings++;
cout << " Total runs: " << run << endl;
cout << endl;
cout << endl;
break;
}
}
number = rand() % 10 + 1;
}
cout << "\nEnd of game!" << endl;
cout << "Total runs made = " << run << endl;
cout << endl;
if (run == 0)
{
cout << "You need to take a break from programming and practice your swing!" << endl;
}
else
{
cout << "Thank you for playing. Goodbye!" << endl;
cout << endl;
}
system("pause");
return 0;
}
int baseball()//DEFINED FUNCTION
{
int innings = 1;
return innings++;
}*/