Recursive return of string

I am really new to the idea of recursion, I cannot get this to work properly. It is supposed to return the index of a string if there is a match. For instance: if the user entered "Search me", and I entered this to search for "me". It would return an index of 7. Any help and support would be appreciated.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <array>


using namespace std;

const int ZERO = 0;
const int INCREASE = 1;
const int OUTLIER = -1;

//index_of method
//Purpose:
//Parameters:
//Returns:
int index_of(string stringToSearchIn, string stringToSearchFor, int index)
{

	if (stringToSearchIn.length() < stringToSearchFor.length())
	{
		cout << "Your string cannot be found." << endl;
		system("PAUSE");
		return OUTLIER;
	}
	else
	{
		bool found = true;
		for (int i = ZERO; i < stringToSearchFor.length; i++)
		{
			found = found && stringToSearchIn(i) == stringToSearchFor(i);
		}
		return index;
	}
	
	return index_of(stringToSearchIn.substr(INCREASE), stringToSearchFor, index++);
}

//main method
//Purpose: Main method to call the recursive function index_of
//Parameters: None
//Returns: 
int main()
{
	//Initializing values
	string userString;
	string userSearch;
	int userIndex = 0;

	//Asking for user input for string
	cout << "This program will find the occurence of one string inside of another." << endl;
	cout << "Enter the string to be searched: " << userString;
	//Getting the string
	getline(cin, userString);

	//Asking for user input for search input
	cout << "Now enter the string you want to search for: " << userSearch;
	//Getting the string
	getline(cin, userSearch);

	//Displaying results
	cout << "The index of the substring is = " << index_of(userString, userSearch, userIndex);

	//Keeping console window open until key press
	system("PAUSE");
	return ZERO;
}
Topic archived. No new replies allowed.