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

bookChallenge: Practice with the Continue Keyword in C++ Loops

Uppgift

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

Awesome!

Completion rate improved to 9.09

bookChallenge: Practice with the Continue Keyword in C++ Loops

Svep för att visa menyn

Uppgift

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 desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5
single

single

some-alt