Private code

I have a segment of code that i do not want the program to execute unless the user wants it to and the goto statement brings them there. So id there any function i can nest the segment in to prevent itd execution unless requested to do so.
which one.
Create a function!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

void function()
{
	std::cout << "You entered the number to run your segment of code...\n";
}

int main ()
{
	int number = 0;

	std::cout << "Please enter a number: ";
	std::cin >> number;

	if( number == 0 )
		function();
	else
		std::cout << "Wrong number, bye...\n";
        
	return 0;
}


Entering 0 will run the code you wish to run.
Don't worry i figured it out.
Topic archived. No new replies allowed.