Not returning to main function, after running a different function

Hi, I have created a rock, paper, scissors game which is an exercise in the book I am going through. It is partially running ok, but im having an issue with the program not returning to the main function. I call Fill() and that runs fine, but I expected the rest of the main function to be run after that, but the program just ends. I am not sure what I have done wrong, or if I have misunderstood how functions run together. Any help would be appreciated.

Also an easier question if someone could answer :) in my for loop in the main function i wanted it to only run the same amount of times as how many items to vector holds, so tried, Pick.size but i get errors talking about pointers, and I have not covered that yet. Can i not run the for loop like I want?

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
  #include "std_lib_facilities.h"

using namespace std;

vector<string>Pick;

void Fill()
{
	int i = 1;
	int input ;
	while (i < 10)
	{
		i++;
		cout << "Enter a number between 1 and 9 \n";
		cin >> input;
		if (input == 1 ||  input == 4 || input == 7)
		{
			Pick.push_back("Rock");
		}
		if (input == 2 || input == 5 || input == 8)
		{
			Pick.push_back("Scissor");
		}
		if (input == 3 || input == 6 || input == 9)
		{
			Pick.push_back("Paper");
		}
	}
}

int main()
{
	Fill();

	char userPick = ' ';
	for (int i = 0; i < 10; i++)
	{
		switch (userPick)
		{
			cout << "Please enter your pick\n";
			cout << "Press r for Rock\n";
			cout << "Press p for Paper\n";
			cout << "Press s for Scissors\n";

			cin >> userPick;
		case 'r':
			cout << "You picked rock. \t The computer picked : " << Pick[i];
			if (Pick[i] == "Scissor")
			{
				cout << "You win \n";
			}
			else
			if (Pick[i] == "Paper")
			{
				cout << "You lose \n";
			}
			else
			{
				cout << "Draw, pick again \n";
			}
			break;
		
		case 'p':
			cout << "You picked paper. \t The computer picked : " << Pick[i];
			if (Pick[i] == "rock")
			{
				cout << "You win \n";
			}
			else
			if (Pick[i] == "scissor")
			{
				cout << "You lose \n";
			}
			else
			{
				cout << "Draw, pick again \n";
			}
			break;

		case 's':
			cout << "You picked scissor. \t The computer picked : " << Pick[i];
			if (Pick[i] == "paper")
			{
				cout << "You win \n";
			}
			else
			if (Pick[i] == "rock")
			{
				cout << "You lose \n";
			}
			else
			{
				cout << "Draw, pick again \n";
			}
			break;	

		default:
			break;
		}
	}
	keep_window_open();
	return 0;
}
Execution jumps from line 38 to the case that matches the current value of 'userPick'.
That value is one whitespace and the only case that does match is the default on line 97.

You have to update the value of 'userPick' before the switch statement.
Line 40 to 45 is never executed hence the loop on line 36 will iterate 10 times with userPick = ' '.
Ah ok, makes sense now that you have said that. I have moved the input for userPick to outside the switch. Thank you for the help.
> so tried, Pick.size but i get errors talking about pointers
if you have code that produces an error, then post that code along with the error message verbatim
in my for loop in the main function i wanted it to only run the same amount of times as how many items to vector holds
1
2
3
for (size_t i = 0; i < Pick.size(); i++) // Die you forget the ()?
	{
...

in my for loop in the main function i wanted it to only run the same amount of times as how many items to vector holds
1
2
3
for (size_t i = 0; i < Pick.size(); i++) // Die you forget the ()?
{
...


Yes I did, thank you for that :)
Topic archived. No new replies allowed.