Challenge: Practice with the Continue Keyword in C++ Loops
Oppgave
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_id
as an empty string. - Initialize the variable
index
as0
. This will act as an iterator to track the current position in thecorrupted_id
string. - Use a
while
loop to iterate through the string untilindex
reaches 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, incrementindex
andcontinue
to skip adding it. - If the character is not
'!'
, append it tofixed_id
. - Increment
index
by one on each iteration. - After the loop finishes, return
fixed_id
as the cleaned ID.
Løsning
solution.cpp
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 9.09
Challenge: Practice with the Continue Keyword in C++ Loops
Sveip for å vise menyen
Oppgave
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_id
as an empty string. - Initialize the variable
index
as0
. This will act as an iterator to track the current position in thecorrupted_id
string. - Use a
while
loop to iterate through the string untilindex
reaches 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, incrementindex
andcontinue
to skip adding it. - If the character is not
'!'
, append it tofixed_id
. - Increment
index
by one on each iteration. - After the loop finishes, return
fixed_id
as the cleaned ID.
Løsning
solution.cpp
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
single