ok in this program I'm trying to make the pointer variable totalW a function parameter that will return the number of w's found in the string entered by the user but it doesn't seem to work ....I know it has to do something with the pointers but I'm at a loss as to how to fix it
output:Code:#include <cstdlib> #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 1001; int numberOfW(int *totalW); int main() { int total = 0; numberOfW(&total); cout << total << " yay did it work?"; system("PAUSE"); return 0; } int numberOfW(int *totalW){ char letter[SIZE]; cout << "Input a string of characters: " << endl; cin.getline(letter, 1000); for (int i = 0; i <= letter[i]; i++){ if(isalpha (letter[i]) && letter[i] == 'w'){ totalW++; } else cout <<"X"; } return *totalW; system("PAUSE"); }
Input a string of characters:
wewe
XX0 yay did it work?Press any key to continue . . .
any suggestions:?