Baseball program (intro to creating Value-Returning Functions)

My question is: Does my program use the int baseball() function that I created? Everything works now.

//My baseball program

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
#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.*/
using namespace 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;
			}
			else if (tries == 2 && swing != number)
			{ 
				cout << "Strike 2!" << endl;
				cout << endl;
			}
			else if (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++;

}*/
Last edited on
Hey. Could you edit your post and use code tags? Makes it much easier to read http://www.cplusplus.com/articles/jEywvCM9/
yes, thank you. Much easier. I didn't know that. =)
Topic archived. No new replies allowed.