Declaring void functions into another variables

have an enteroption function. In my main function im trying to declare the result of enteroption into a new variable.

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
int EnterOption()
{
	//Tell use to enter in a choice
	cout<<"Choices Listed";

	//Display all the choices
	//The counter is set to 1. Printing out the text in a quicker way. Displaying text on screen.
	int counter=1;
	while(counter<=9)
	{
		cout<<"\n\n\t" <<counter<< ".] Print all the numbers between 1 and 1000 that are divisible by "<< counter;
	counter++;
	}

	//Display the other three options
	cout<<"\n\n\t10.] Print all the numbers between one and thousand";
	cout<<"\n\n\t11.] Print all the even numbers between one and thousand";
	cout<<"\n\n\t12.] Print all the odd numbers between one and thousand";

	//Declare a variable for the choice user will enter
	int number;

	//Perform a do while loop. If the user enters in a number not in the range it will ask user to enter it again
	do
	{
		cout<<"\n\nEnter Choice: ";
		cin>>number;

		
	}

	//Repeat the loop if its not in the range
	while (number<0 || number>12);
	
		return number;

}

//Function will print out the number that is divisible
void print_series1(int divisible)
{
	//Making a variable that will divide the divisble number by each number to 1000
	int counter;
	int remainder;
	counter=1;
	cout<<endl;

	//While counter is less then 1000 it will print out the divisible numbers
	while (counter<=1000)
	{
		//formula for finding the remainder
		remainder=counter%divisible;

		//If remainder=0, the print out the divisible number
		if (remainder==0)
		{
			//Print out the counter. These counter will be divisible numbers
			cout<<counter;
			cout<< " ";
		
		}
		//Incrememt counter by one
	counter++;
	
	}



}

EnterOption();

	//You want a value from enteroption. Set a variabel that will store enteroption value into new variable
	int StoreEnterOptionValue;
	StoreEnterOptionValue==EnterOption;


I have the value of enteroption saved in the variable storeneteroptionvalue; however, I don't want the the program to ask me for a choice again.
This is the output I get on the screen

Choice Listed:
1.) Print all the numbers between one and thousand";
2.)Print all the even numbers between one and thousand";
3.)Print all the odd numbers between one and thousand";
.........

Enter Choice: 0

Choice Listed:
1.) Print all the numbers between one and thousand";
2.)Print all the even numbers between one and thousand";
3.)Print all the odd numbers between one and thousand";
.........

Enter Choice:







Rather then the program askingme twice I want it to ask me once. I know the problem lays in that storeenteroptionvalue=enteroption. I just want to store the value from enteroption intothat function.
line 75... do like this.

StoreEnterOptionValue = EnterOption();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Call the function enteroption to allow the user to enter in a number
	EnterOption();

	//You want a value from enteroption. Set a variabel that will store enteroption value into new variable
	int StoreEnterOptionValue;
	StoreEnterOptionValue=EnterOption();

	//If Select Series=0, terminate the program
	if (StoreEnterOptionValue==0)
	{
		cout<<"\n\n\tExecution Error";
		_getch();
		return 0;



This is how I revised my code and yet i'm still getting the same error. I'm using "zero" value as my test sample. It asks me to enter in a choice and I enter in zero. As I clarified before, it asks me for the enter choice again. When I enter in zero this time. It states Execution error and it terminates :) I just want the program to ask me once, rather then twice
I g have it solved manga.I deleted the EnterOption() in the beginning of the code. Appreciate your insight of this though :)
Topic archived. No new replies allowed.