
In my program, I am asking for the user to input a string, then pass that string to the getLength function, and then display the functions return value. However, if I did cin before referencing the getLength function, it would tell me invalid conversion. Even if I changed the parameter type to match, I am still getting the same error messages.
Now in the getLength function, I know I need to return some value... what I have in there now I know doesn't work, it's just showing that I understand I need to return some value back to the main function.
Can someone please point me in the right direction?
Thank you =)
#include <iostream> using namespace std; int *getLength(int); int main() { int townLength; int *ptr; cout << "Enter your towns name.\n"; getLength(townLength); ptr = getLength(townLength); cout << "Your town has" << ptr << "characters" << endl; delete [] ptr; ptr = 0; system ("PAUSE"); return 0; } //********************************************* // Function nameLength * // This function counts the number of * // characters in a string. * // * //********************************************* int *getLength(int) { string townName; int *ptr; cin >>townName; //Read as a string ptr = townName.size(); return ptr; }