Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Practice with the Continue Keyword in C++ Loops | While Loop
C++ Loops

bookChallenge: 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.

  1. Initialize the variable fixed_id as an empty string.
  2. Initialize the variable index as 0. This will act as an iterator to track the current position in the corrupted_id string.
  3. Use a while loop to iterate through the string until index reaches the size of the string. You can get the size of the string using the length() method.
  4. Inside the loop, check if the current character is '!'. If it is, increment index and continue to skip adding it.
  5. If the character is not '!', append it to fixed_id.
  6. Increment index by one on each iteration.
  7. After the loop finishes, return fixed_id as the cleaned ID.

Løsning

solution.cpp

solution.cpp

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 5
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

Awesome!

Completion rate improved to 9.09

bookChallenge: 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.

  1. Initialize the variable fixed_id as an empty string.
  2. Initialize the variable index as 0. This will act as an iterator to track the current position in the corrupted_id string.
  3. Use a while loop to iterate through the string until index reaches the size of the string. You can get the size of the string using the length() method.
  4. Inside the loop, check if the current character is '!'. If it is, increment index and continue to skip adding it.
  5. If the character is not '!', append it to fixed_id.
  6. Increment index by one on each iteration.
  7. After the loop finishes, return fixed_id as the cleaned ID.

Løsning

solution.cpp

solution.cpp

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 5
single

single

some-alt