Question: The comment explains what the following loop does. Use a function instead. ` ` ` / / Counts the number of spaces int spaces =
The comment explains what the following loop does. Use a function instead.
Counts the number of spaces
int spaces ;
for int i ; i input.length; i
if inputsubstri spaces;
int countcharconst string& str char c
int count ;
for int i ; i strlength; i
if stri c
count;
return count;
int main
string str;
getlinecin str;
cout countspacesstr endl;
return ;
times Failed to compile
helperfunction.cpp: In function 'int main:
helperfunction.cpp::: error: 'countspaces' was not declared in this scope
cout countspacesstr endl;
~ ~ ~ ~ ~ ~
Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often don't recognize the problem until reaching a later line.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
