Im sorry, my english writting is horrible, please read the above and you will understand what i am asking you help on:
int x; //This is declared somewhere, and other functions set its value.
int function a() { //This is called by mainFunction.
if x==1 {
return 0;
}
else {
return 1;
}
}
int masterFunction() {
a();
//if a() returns 0 do this
//else do that
}
How do i do what i wrtote in the commented lines of mainFunction?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Im sorry, my english writting is horrible, please read the above and you will understand what i am asking you help on:
int x; //This is declared somewhere, and other functions set its value.
int function a() { //This is called by mainFunction.
if x==1 {
return 0;
}
else {
return 1;
}
}
int masterFunction() {
a();
//if a() returns 0 do this
//else do that
}
How do i do what i wrtote in the commented lines of mainFunction?
Thanks!
Hi,
1. Function definition is like this:
declaration-specifiers function-name (parameter-type-list)
declaration-list<opt>
compound-statement
so no keyword "function".
2. If statement:
if (expression) statement
so expression must be between parentheses.
3. Return with expression:
expression is returned to caller as value of function call expression
so you either write if (a () == 0) do this or assign a() to variable.
tkorrovi
int x; //This is declared somewhere, and other functions set its value.
int a() { //This is called by mainFunction.
if (x==1) {
return 0;
}
else {
return 1;
}
}
int masterFunction() {
if (a() == 0){
//do this
}
else{
cout << "not zero" << endl;
}
}
Derek