0

Hello Everyone,
I was wondering if anyone could show me how to call a function from inside a boolean statement. Something like the example below. I know it isn't right and was wondering if anyone could give me a hint or an example of coding it correctly. Thank you, hill0ster! :lol:

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;
        }
}

Edited by Dani: Formatting fixed

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by hill0ster
0
#include <iostream>
#include <cstdlib>
using namespace std; // for toy programs

bool getEmployeeData(int &ID)
{
   cout << "Enter employee ID: ";
   cin  >> ID;
   if ( ID >= 0 )
   {
	  return true;
   }
   return false;
}

int main()
{
   int id;
   if ( getEmployeeData(id) == false )
   {
	  cout << "*** Program Terminated ***" << endl;
	  exit (0);
   }
   cout << "id = " << id << endl;
   return 0;
}
0

Dave,
Thanks for your help. However I must call the bool isValidStatus from the bool getEmployeeData. If I had a choice I would call it from main. I have seen no examples of how to do this. If anyone knows how, I would much appreciate it. Paul.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.