I need the count_digits function to count the number of digits in a series of strings. The function seems logically sound to me but my program is no compiling. I get errors for invalid initialization and passing arguments. Any assistance would be greatly appreciated.
H:\C++ Examples\formatfile.cpp||In function `int main()':|
H:\C++ Examples\formatfile.cpp|26|error: invalid initialization of reference of type 'std::string&' from expression of type 'int'|
H:\C++ Examples\formatfile.cpp|12|error: in passing argument 1 of `void count_digit(std::string&, int)'|
H:\C++ Examples\formatfile.cpp||In function `void count_digit(std::string&, int)':|
H:\C++ Examples\formatfile.cpp|70|error: declaration of 'int sum' shadows a parameter|
H:\C++ Examples\formatfile.cpp|70|warning: converting to `int' from `double'|
||=== Build finished: 3 errors, 1 warnings ===|
On line 26 you are passing an int to count digit as the first parameter instead of a string.
Also in your count_digit function, you aren't returning sum from it or passing it by reference, so you won't actually change the value of it in main. You also have a different int called sum inside the function that isn't the same as the parameter (hence the 'int sum' shadows a parameter error)