| | |
Still need info on calling a function from bool!
![]() |
•
•
Join Date: Oct 2004
Posts: 18
Reputation:
Solved Threads: 0
I have never seen an example of this, but I need to call a function or another bool from inside a bool! If anyone knows how this might go, please let me know. P.S. This website is awsome! Thanks, Paul
//something like this, however this is not working...
bool getEmployeeData(int ID)
{
cout << "Enter employee ID: " << endl;
cin >> ID;
if (ID >= 0)
{
return true;
bool isValidStatus;
}
else
{
cout << "*** Program Terminated ***" << endl;
exit (0);
return false;
}
}
bool isValidStatus (int status)
{
cout << "Enter payroll status: " << endl;
cin >> status;
if (status == 's' || status == 'S' || status == 'c' || status == 'C' || status == 'h' || status == 'H')
{
cout << status;
return tryAgain;
}
else
{
bool tryAgain (int quit);
return false;
}
}
//something like this, however this is not working...
bool getEmployeeData(int ID)
{
cout << "Enter employee ID: " << endl;
cin >> ID;
if (ID >= 0)
{
return true;
bool isValidStatus;
}
else
{
cout << "*** Program Terminated ***" << endl;
exit (0);
return false;
}
}
bool isValidStatus (int status)
{
cout << "Enter payroll status: " << endl;
cin >> status;
if (status == 's' || status == 'S' || status == 'c' || status == 'C' || status == 'h' || status == 'H')
{
cout << status;
return tryAgain;
}
else
{
bool tryAgain (int quit);
return false;
}
}
>but I need to call a function or another bool from inside a bool!
Work on your terminology first, because I have no clue what you want. Let's get this straight, bool is a type. bool has two values: true and false. You don't call squat from inside a bool because all it does is represent true or false, nothing else. You can have functions that return bool, or statements that result in bool, but they're not bool and shouldn't be referred to as such if you want to have meaningful conversation with intelligent parties.
Work on your terminology first, because I have no clue what you want. Let's get this straight, bool is a type. bool has two values: true and false. You don't call squat from inside a bool because all it does is represent true or false, nothing else. You can have functions that return bool, or statements that result in bool, but they're not bool and shouldn't be referred to as such if you want to have meaningful conversation with intelligent parties.
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
I do not really understand the problem that you have. But a few explanations might help
maybe you want something like this
Hope this helps.
btw. Naru seems to be here to insult people.
K.
C++ Syntax (Toggle Plain Text)
if (ID >= 0) { return true; // you're returning from the call here bool isValidStatus; // this statement is never reached // here you are declaring a boolean variable isValidStatus. // this is not a call to the function of the same name; } else{ cout << "*** Program Terminated ***" << endl; exit (0); // same problem is here. the prog is terminated here return false; // this statement is never reached }
maybe you want something like this
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; bool isValidStatus( char status ) { if (status == 's' || status == 'S' || status == 'c' || status == 'C' || status == 'h' || status == 'H'){ return true; } cout << status << " is not valid ! try again" << endl; return false; } char getStatus() { char status; do { cout << endl << "Enter payroll status: "; cin >> status; } while ( ! isValidStatus(status) ); // repeat until a valid status is entered return status; } int getEmployeeData() { int ID = 0; cout << "Enter employee ID (0 to exit program ): "; cin >> ID; if ( ID == 0 ) { cout << "bye.." << endl; exit (0); } // terminate program cout << "employee ID= " << ID << endl; return ID; } int main() { int ID = getEmployeeData(); // read employee ID char status = getStatus(); // read Status cout << "the status entered was : " << status << endl; return 0; // main should return an exit-code }
btw. Naru seems to be here to insult people.
K.
>Yes, you can call other functions from inside a bool.
Then you're not using the proper terminology. A bool is true or false, that's it. There's no way to call a function from inside a value. I suspect that what you're thinking of is calling a function in a conditional test:
or calling a function that returns bool from another function that returns bool:
>but I would appreciate some respect if you respond to me!
I do respect you for various reasons, but I don't respect your complete lack of an attempt to express yourself in a way that is conducive to getting help. I'm not going to guess what you want simply because you don't know how to ask the question in a way that we can understand. So let's go over this one more time.
A bool is a data type with two values. Functions can return bool, expressions can result in bool, but the only thing that can be inside bool is true or false that map to non-zero and zero integral values, respectively. Tell me how to call a function from within 0 and I'll reconsider this explanation.
>btw. Naru seems to be here to insult people.
I'm not responsible for your misconceptions. Though I don't like the insinuation that I don't help people here.
Then you're not using the proper terminology. A bool is true or false, that's it. There's no way to call a function from inside a value. I suspect that what you're thinking of is calling a function in a conditional test:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; bool f() { // Do something and return true or false } int main() { if ( f() ) cout<<"f() was true"<<endl; }
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; bool f1() { // Do something and return true or false } bool f2() { if ( f1() && something else ) return true; else return false; } int main() { if ( f() ) cout<<"f() was true"<<endl; }
I do respect you for various reasons, but I don't respect your complete lack of an attempt to express yourself in a way that is conducive to getting help. I'm not going to guess what you want simply because you don't know how to ask the question in a way that we can understand. So let's go over this one more time.
A bool is a data type with two values. Functions can return bool, expressions can result in bool, but the only thing that can be inside bool is true or false that map to non-zero and zero integral values, respectively. Tell me how to call a function from within 0 and I'll reconsider this explanation.
>btw. Naru seems to be here to insult people.
I'm not responsible for your misconceptions. Though I don't like the insinuation that I don't help people here.
I'm here to prove you wrong.
![]() |
Similar Threads
- Calling a function in html file from c# code (C#)
- calling function name? i need help (PHP)
- Helping with calling a function (C)
- Calling C function from MATLAB (C)
Other Threads in the C++ Forum
- Previous Thread: compilers in C
- Next Thread: Problems with switch statement
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple net news node number numbertoword output parameter payment pointer problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






