Challenge: Keep Score
Completed
Start an int variable score at 0. Add 10 to it, print it, then add 25 more and print it again. Use score = score + ... to update it.
Input
None.
Output
Score: 10 Score: 35
Example
Output
Score: 10 Score: 35
Editor
C++
Hints
Create the variable once with int, then just use its name.
score = score + 10; adds 10.
Solution explanation
The right side is worked out first using the old value, then the result is stored back in the same box.
Show solution
#include <iostream>
using namespace std;
int main() {
int score = 0;
score = score + 10;
cout << "Score: " << score << "\n";
score = score + 25;
cout << "Score: " << score << "\n";
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module