Results 1 to 5 of 5

Thread: Problem in boolean function

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    Problem in boolean function

    Hi friends,
    I am new to this forum. I recently started learning c++ language. I have written following program in c++, but I get problem in in boolean function. I don't know what is the reason of error. Please help me.


    Code:
    using namespace std;
    
    
    bool checkValue(int, int, int);
    
    
    int main()
    {
       
            int iNumber[20];
            int a = 0;
            int k = 0;
            
                    for (int k=0; k<20;) {
                            cout << "Enter 20 integers between 10 and 100: ";
                            cin >> a;
                                    if ((a>=10) && (a<=100)){      
                                            checkValue(a,iNumber[k], k);   
                                            if (checkValue=false) {
                                                    iNumber[k]=x;  
                                                    n++;    
                                            }
                                            else if (checkValue=true) {
                                            cout << "Invalid Number!" << endl;      
                                            }
                                    }
                    }
         
                    cout << endl;
                    for (int k=0; k<20;){
                            cout << "The non-duplicate values are:" <<  iNumber[k] << endl;
                            k++; 
                    }
            return 0;
    }      
    
    
    bool checkValue(int x, int iNumber[n], int n) {
    
       for (int i=0; i<n; i++) {
          if (x == iNumber[n]) {
                      cout << "Duplicate Number!" << endl;  
                      return true;
              }
              else {
                    return false;
              }
    }       //end of checkValue function

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Problem in boolean function

    Hey you have make some silly mistake in your code and that's why you are getting such type of problem. In this case you have written following code in your program to fix this problem.

    Code:
    for (int k=0; k<n; k++) {
          if (y == iNumber[z]) {
                      cout << "another number" << endl;  
                      return true;
              }
              else {
                    return false;
              }
    }
    After this use == for comparison and you also have to use () for call a function.

    Code:
    bool Functions(void);
    
    if(Functions() == true) {

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Problem in boolean function

    You have made two wrong mistake in your code and that's why you are getting such type of problem. In this case you have to following code in your program to get rid out of this problem. First create one variable known as "checkValues" and assign true value as following.

    Code:
    if (checkValues=true) {
    If above condition failed then you can use following code.

    Code:
    if (checkValues==false) {

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Problem in boolean function

    You have assign same value for two different variable and that's why you are getting such type of error message. Instead of assigning any value you have to use Boolean variable without any value like below

    Code:
    if(checkValue){
    But there is one problem. Boolean value must return any value and for this you have to call function without assigning a value to it.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Problem in boolean function

    You have written wrong code and that's why you are getting such type of error message. In this case you have to use following code in your program to fix this problem.


    Code:
    bool checkValue(int k, int iNumber[], int n) 
    {
        for (int a=0; a<s; i++)
        {
            if (k == iNumbers[z])
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

Similar Threads

  1. Custom Boolean Values in Microsoft Excel
    By Thedevotee in forum MS Office Support
    Replies: 2
    Last Post: 15-02-2012, 05:05 PM
  2. JavaScript: RegExp and Boolean Object
    By Ivann in forum Software Development
    Replies: 5
    Last Post: 18-12-2009, 03:36 AM
  3. How to check the value of boolean variable
    By Amie in forum Software Development
    Replies: 4
    Last Post: 26-11-2009, 06:29 PM
  4. how to convert a boolean value to a string in java?
    By Janus in forum Software Development
    Replies: 3
    Last Post: 29-07-2009, 08:07 PM
  5. Store default boolean value in SQL server
    By Bilal in forum Software Development
    Replies: 2
    Last Post: 09-06-2009, 10:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,296,301.90843 seconds with 16 queries