Hello, all. I'm just working on this assignment and I got pretty much the entire program fixed EXCEPT trying to pass the value back to the calling function. Please see the problem below. Here's the code:
#include <iostream>
#include <string>
using namespace std;
int countlets (string);
int numLet;
int main ()
{
string strInput, strChars;
cout << "Enter a string (only the number of letters will be counted): " << endl;
getline (cin, strInput);
strChars = countlets (strInput);
cout << strChars << endl;
return 0;
}
int countlets (string y)
{
int i;
char nextChar;
for (i = 0; i < y.length(); i++)
{
nextChar = y.at(i);
if (isalpha(nextChar))
{
numLet++;
}
}
cout << numLet << endl; // I just used this to test that the operations
// actually worked in the loop.
return 0;
}
// So the only problem is just trying to get the value from countlets () back to main(). What's happening is that when I enter a string, it just comes up blank in the output. Thanks for the guidance and much appreciative for any help.
Oh, okay, thank you. Actually, what was funny was I just did the return numlet; like you said and it came up with a smiley face. ??? But it is working fine now. I just didn't see the part where you said to declare setChars to int. Thanks!