Challenge: Practice with the Continue Keyword in C++ Loops
Swipe to start coding
The ID string has been corrupted and is currently saturated with exclamation marks (!). You were chosen to restore the original data it was holding.
All the code should be implemented inside the fixId function.
- Initialize the variable
fixed_idas an empty string. - Initialize the variable
indexas0. This will act as an iterator to track the current position in thecorrupted_idstring. - Use a
whileloop to iterate through the string untilindexreaches the size of the string. You can get the size of the string using thelength()method. - Inside the loop, check if the current character is
'!'. If it is, incrementindexandcontinueto skip adding it. - If the character is not
'!', append it tofixed_id. - Increment
indexby one on each iteration. - After the loop finishes, return
fixed_idas the cleaned ID.
Solution
solution.cpp
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 9.09
Challenge: Practice with the Continue Keyword in C++ Loops
Swipe to show menu
Swipe to start coding
The ID string has been corrupted and is currently saturated with exclamation marks (!). You were chosen to restore the original data it was holding.
All the code should be implemented inside the fixId function.
- Initialize the variable
fixed_idas an empty string. - Initialize the variable
indexas0. This will act as an iterator to track the current position in thecorrupted_idstring. - Use a
whileloop to iterate through the string untilindexreaches the size of the string. You can get the size of the string using thelength()method. - Inside the loop, check if the current character is
'!'. If it is, incrementindexandcontinueto skip adding it. - If the character is not
'!', append it tofixed_id. - Increment
indexby one on each iteration. - After the loop finishes, return
fixed_idas the cleaned ID.
Solution
solution.cpp
Thanks for your feedback!
single