I don't understand why I need to enter input twice

Could some one help me understand why my program keeps requiring me to enter my input twice? This is the part that's causing the error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int NumericalMenu::run() const{
	int choice;
	
	const unsigned int v = myVector.size();
	while (v > 0){
		cin >> choice;
		if ((unsigned)choice <= v){
			break;
		}
		else if ((unsigned)choice == (v + 1)){
			choice = -1;
			break;
		}
		else if ((unsigned)choice > (v + 1)){
			cout << error << endl;
			break;
		}
		else{
			cout << error << endl;
			break;
		}
	};
return choice;
}


Header:
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
#ifndef NUMERICALMENU_H_
#define NUMERICALMENU_H_

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class NumericalMenu{
private:
	int i, num = 0;
	
public:
	vector<string> myVector;
	string error = "Error!";
	string cancel = "Cancel";
	string prompt = "Choose an option:";

	NumericalMenu();
	void setPrompt(string);
	int addOption(string);
	void setCancelText(string);
	void setErrorText(string);
	void setRepeatPromptOnError(bool);
	int run() const;
	int size() const;
	
};

#endif /* NUMERICALMENU_H_ */
Topic archived. No new replies allowed.