Not Going to a Function

I am building a program and once a certain "else" is "activated", I want the program to not go to the other function. So if the else in Function1 is used, dont go to function2. For example:

//not written perfectly, but you'll get the point

Function1()
{
if(a = 2 * 100)
{
b = a + 100 ;
}
else
{
cout << a << " does not equal 200" << endl;
system ("PAUSE") ;

//the pause only pauses the program, not stop the function2, so when enter is
//pressed, the program then displays function2

// in this else statement, I want the program to not go to Function2 and to just display the cout, pause, and //end

}
return b;
}

Function2()
{
//do something with b
}

int main()
{
function1(0)
function2(0)
}


I want, at the else statement if it is used to then have the program skip function2. To do this, do I need to have if and else statements in the int main or is there another way?
Any feedback will be appreciated! Thank you!

There are many ways.

My first thought was to pass a variable by reference into function 1.


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

function1(int x, int & cheeto){ //Notice the & symbol. You have to put it there.
     
     if (//......){
          //some code......cheeto is NOT changed.
}
     
     else{
        //some code......
        cheeto = 2;//Change it to a random value. 
                          //So in main(), cheeto is now 2. The second function will not run.
}

}




int main(){){

     int cheeto = 1;

     function1(0, cheeto);


//If cheeto still equaled 1, then the "else" in function1 did not execute.
if (cheeto == 1){
     function2(0);
}



}








Some thing like that.
Topic archived. No new replies allowed.