Function of string ???

This is a discussion on Function of string ??? within the C++ Programming forums, part of the General Programming Boards category; hi everyone, i just want to ask that can i make the following code into function? Code: if(physicalCycle(dob, currentDate) < ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    Function of string ???

    hi everyone, i just want to ask that can i make the following code into function?

    Code:
        if(physicalCycle(dob, currentDate) < 100 && physicalCycle(dob, currentDate) > 0)
        {
            cout<<"Ascending";
        }
        else if(physicalCycle(dob, currentDate) < 0)
        {
            cout<<"Descending";
        }
        else
        {
            cout<<"Critical day";
        }
    if yes, wat data type should i use? string?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,826
    Yes, you could. It could return a std::string, or void if you just plan to print from within the function.
    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

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    can u give me an example of returning those as void..

  4. #4
    Chi! whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    8,222
    Well I'm making a total guess as to what dob and currentDate are, but I guess thy're strings. You'd pass them in as const references though, and specify the return type as void.
    Code:
    void biorythmState(const string& dob, const string& currentDate) {
        if(physicalCycle(dob, currentDate) < 100 && physicalCycle(dob, currentDate) > 0)
        {
            cout<<"Ascending";
        }
        else if(physicalCycle(dob, currentDate) < 0)
        {
            cout<<"Descending";
        }
        else
        {
            cout<<"Critical day";
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21