Still need info on calling a function from bool!

Reply

Join Date: Oct 2004
Posts: 18
Reputation: hill0ster is an unknown quantity at this point 
Solved Threads: 0
hill0ster hill0ster is offline Offline
Newbie Poster

Still need info on calling a function from bool!

 
0
  #1
Oct 13th, 2004
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;
}
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Still need info on calling a function from bool!

 
0
  #2
Oct 13th, 2004
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 18
Reputation: hill0ster is an unknown quantity at this point 
Solved Threads: 0
hill0ster hill0ster is offline Offline
Newbie Poster

Re: Still need info on calling a function from bool!

 
0
  #3
Oct 16th, 2004
Yes, you can call other functions from inside a bool. I may be a newbie, but I would appreciate some respect if you respond to me! Otherwise don't bother responding.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: Still need info on calling a function from bool!

 
0
  #4
Oct 16th, 2004
I do not really understand the problem that you have. But a few explanations might help
  1. if (ID >= 0) {
  2. return true; // you're returning from the call here
  3. bool isValidStatus; // this statement is never reached
  4. // here you are declaring a boolean variable isValidStatus.
  5. // this is not a call to the function of the same name;
  6. }
  7. else{
  8. cout << "*** Program Terminated ***" << endl;
  9. exit (0); // same problem is here. the prog is terminated here
  10. return false; // this statement is never reached
  11. }

maybe you want something like this

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isValidStatus( char status ) {
  5. if (status == 's' || status == 'S' || status == 'c' || status == 'C' || status == 'h' || status == 'H'){
  6. return true;
  7. }
  8. cout << status << " is not valid ! try again" << endl;
  9. return false;
  10. }
  11.  
  12. char getStatus() {
  13. char status;
  14. do {
  15. cout << endl << "Enter payroll status: ";
  16. cin >> status;
  17. } while ( ! isValidStatus(status) ); // repeat until a valid status is entered
  18. return status;
  19. }
  20.  
  21. int getEmployeeData() {
  22. int ID = 0;
  23. cout << "Enter employee ID (0 to exit program ): ";
  24. cin >> ID;
  25. if ( ID == 0 ) {
  26. cout << "bye.." << endl;
  27. exit (0);
  28. } // terminate program
  29. cout << "employee ID= " << ID << endl;
  30. return ID;
  31. }
  32.  
  33. int main() {
  34. int ID = getEmployeeData(); // read employee ID
  35. char status = getStatus(); // read Status
  36. cout << "the status entered was : " << status << endl;
  37. return 0; // main should return an exit-code
  38. }
Hope this helps.
btw. Naru seems to be here to insult people.
K.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Still need info on calling a function from bool!

 
0
  #5
Oct 16th, 2004
>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:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool f()
  6. {
  7. // Do something and return true or false
  8. }
  9.  
  10. int main()
  11. {
  12. if ( f() )
  13. cout<<"f() was true"<<endl;
  14. }
or calling a function that returns bool from another function that returns bool:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool f1()
  6. {
  7. // Do something and return true or false
  8. }
  9.  
  10. bool f2()
  11. {
  12. if ( f1() && something else )
  13. return true;
  14. else
  15. return false;
  16. }
  17.  
  18. int main()
  19. {
  20. if ( f() )
  21. cout<<"f() was true"<<endl;
  22. }
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC