How would we chain functions?

This is a discussion on How would we chain functions? within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a question concerning chaining functions. Here is my code below: Code: #include <iostream> #include <string> using namespace ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    How would we chain functions?

    Hi, I have a question concerning chaining functions. Here is my code below:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    string enter_secret();
    
    string hidden_word();
    
    string word, secret;
    
    int main()
    {
    	enter_secret();
    	
    	return 0;
    }
    
    string enter_secret()
    {
    cout << "Enter a word" << endl;
    cin >> word;
    
    string str (word);
    
    cout << "String Length: " << str.length() << endl;
    
    	return secret;
    }
    
    string hidden_word(string secret)
    {
    	return string(secret.length(), '-');
    }

    Now when I run the program, it would ask me to enter a word, then it would output the number of strings the word has.

    So for example, the word trees have five letters so the answer is five.

    Now how would we hook that to the function below called string hidden_word(string secret)?

    I want the program to also output the number of dashes in place of the number of letters.

    How would we hook the function string hidden_word to main? Or should it get hooked to the function enter_secret?

    Thanks.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You have to use the return values of the functions.

    However, if you expect not to see the input that you type on the screen, then you'll need nonstandard libraries, because with standard libraries input is only read after it has been output to the screen.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. Need help with functions
    By jusfry01 in forum C Programming
    Replies: 2
    Last Post: 05-22-2010, 06:25 PM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  5. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM

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