How can I transfer what I have in my main() into a string function?

Please read my entire question:
My main function works properly. But I need it to be in the getSecretMessage(string str) function. How can I do that?
Again, the main function works fine so I don't need help finishing the main. I just need to move the logic I have from main into the string function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 /**
 * Assignment#6.2
 * DUE: 3/13/16 
 * NAME: <Joshua Cisneros>
 * Purpose: Your professor needs your help to decipher some secret message in a sentence. 
 * The secret message is formed by taking the first letter from each word in the sentence, 
 * in the order they appear. Write the following function per its styling/documentation:
 * 
 */
#include <iostream>

using namespace std;
/**
 * FUNCTION SIGNATURE: string getSecretMessage(string str)
 * PURPOSE: get secret message by taking the first character from each word in the input sentence, in the order they appear
 * PARAMETER:
 *     str, the input sentence 
 * RETURN VALUE:
 *     The secret message
*/

string getSecretMessage(string str)
{
   

}
int main (void) {

 string str[51]; // the code works perfectly here though. 
    int i=0;
    for (i=0;i<51;i++)
    {
      cin >> str[i]; 
    }
    for (i=0;i<51;i++)
    {
     cout << str[i][0];   
    }

  

 

  return 0;

}
Last edited on
If I understand you are using an array to hold each word individually but the problem says that your string getSecretMessage(string str) function can only take one string. Instead of putting each word in an array try making the program with the entire sentence in one string.
Please don't duplicate post, it's ultimately a time waster for those who reply.

http://www.cplusplus.com/forum/beginner/186608/
Topic archived. No new replies allowed.