Thread: String check

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    61

    Unhappy String check

    Below is the code I have come up with but no matter what I put into the strings it comes out saying not equal. Please help! I'd greatly appreciate it.

    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    //#include <iostream.h>
    using namespace std;
    
    bool is_equal(int A[], int B[], int size);
    
    
    int main( )
    {
    
    int A[] = {1,2,3,4,5,6,7,8,9};
    int B[] = {1,2,3,4,5,6,7,8,9};
    
        if(is_equal (A,B,9))
        cout << "They are equal " << endl;
        else
        cout << "They are not equal  " << endl;
        
        
    	system("pause");
    }
    
    
    	bool is_equal (int A[], int B[], int size)
    {
         for (int i =0; 1 < size; i++)
         {
             if (A[i] != B[i])
             
             return false;
          }
          return true;
    }
    Please help I am stuck
    Last edited by Salem; 06-27-2007 at 10:39 AM. Reason: Arg!!! it burns, IT BURNS - remove horrid colour of no benefit.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    First of all, do you know what a string is? I strongly doubt it.

    Secondly, your indentation sucks. Your color choice to paint the code is also bad.

    Lastly, the logic in your is_equal() function is totally wrong. Look it over, trace it manually on paper, and then rewrite it.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    So what about indentation--I am not doing this to please you--I choose the color I like If you do not like it don't read it. No, I am learning what a string is so that is my I need help. Also, remember we are not all as smart as you are and mostly we all do not THINK we are as smart as you are. You should not be a jerk when answering someones post--

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by BJtoVisualcC++ View Post
    So what about indentation--I am not doing this to please you--I choose the color I like If you do not like it don't read it.
    That's not an intelligent attitude when requesting help.

    For what it's worth, the error is here:
    Code:
    1 < size
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    Oh yeah? This is not an intelligent attitude to respond to someone asking for help. Color, indentation, means nothing at this point it is the code that should be responded to. If you are so intelligent as you think you are why not answer the question? show me what is wrong?

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    Apparently this board is run by males whose macho attitude needs to be honeyed to get a descent response of help.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by BJtoVisualcC++ View Post
    So what about indentation
    It sucks, makes it hard to read, and is a pain for you and others to debug. In terms of efficiency of upkeep, it's something you should take seriously.

    Quote Originally Posted by BJtoVisualcC++ View Post
    --I am not doing this to please you--
    Indeed, you are right.

    Quote Originally Posted by BJtoVisualcC++ View Post
    I choose the color I like If you do not like it don't read it.
    Mmm, very good point. I figured I was doing us both a favor by replying, but if you prefer I suppose I should ignore your future pink posts on a gray background.

    Quote Originally Posted by BJtoVisualcC++ View Post
    No, I am learning what a string is so that is my I need help.
    What you posted has nothing to do with strings. A string losely refers to a collection of characters, sometimes terminated by a NULL character (ie. a '\0'), such as in C. In C++, there is a class called string that allows for such operations in a much safer manner.

    Quote Originally Posted by BJtoVisualcC++ View Post
    Also, remember we are not all as smart as you are and mostly we all do not THINK we are as smart as you are.
    I am not a smart person by any means, and have no idea why you would assume such.

    Quote Originally Posted by BJtoVisualcC++ View Post
    You should not be a jerk when answering someones post--
    My impression was that posting code with crappy indenting and a hard-to-read color is being a jerk to those you are asking for help. Perhaps I am wrong.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    First, color and indentation mean everything. They play a huge factor in how easy it is for us to read your code. And since we're doing this voluntarily, we'll choose to answer the questions that are not hard to read because the poster thinks his (or her?) specific tastes are so important that they can affect readability, and who further is too lazy to just format code properly.

    But apparently you don't want help. You just want to come here and complain about people who don't jump to serve you faithfully.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    Faithfully? If I am getting so many low blows why can't someone just please PLEASE show me how--if indentation is the problem show how color I will not post it that way again-just why can't someone say ok do the syntax this way to that way and than I can go from there

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by BJtoVisualcC++ View Post
    Code:
         for (int i =0; 1 < size; i++)
    You mean "i < size" not "1 < size".

    Whining about your indentation didn't seem helpful, so I found your problem instead.

  11. #11
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I'm Not Going To Get Paid!?

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    someone just please PLEASE show me how--if indentation is the problem show how color I will not post it that way again-just why can't someone say ok do the syntax this way to that way and than I can go from there
    Very well, here is an example, without your mistake corrected:
    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    bool is_equal(int A[], int B[], int size);
    
    int main()
    {
        int A[] = {1,2,3,4,5,6,7,8,9};
        int B[] = {1,2,3,4,5,6,7,8,9};
    
        if (is_equal(A, B, 9))
            cout << "They are equal " << endl;
        else
            cout << "They are not equal  " << endl;
    
        system("pause");
    }
    
    bool is_equal(int A[], int B[], int size)
    {
        for (int i = 0; 1 < size; i++)
        {
            if (A[i] != B[i])
                return false;
        }
        return true;
    }
    CornedBee did point out your mistake earlier, actually.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    As for strings, read this reference on the string class to understand what operations it supports and how to use it.

    http://www.cppreference.com/cppstring/index.html

  14. #14
    Registered User
    Join Date
    Jun 2007
    Posts
    61
    Thank You for finding the mistake--if you want to be a tutor-yes indigo0086-otherwise I guess thank you is all I can give you is thank you-and everyone else thank you

  15. #15
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    But in the end, your original post has nothing to do with the question you are asking. What is it that you want to find out, and show us code for that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 11:56 PM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM