#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int points = 0;
int roundsPlayed = 0;
const int MAX_ROUNDS = 10;
const int WIN_POINTS = 500;
const int LOSE_POINTS = 200;
srand(time(0));
cout << "starting points: " << points << endl;
for (int i = 1; i<= MAX_ROUNDS; i++) {
int roundScore = rand() % 101;
points += roundScore;
roundsPlayed++;
cout << "round " << i << ": scored " << roundScore << " points, total = "
<< points << endl;
if (points >= WIN_POINTS) {
cout << "you win! you reached " << points << " points." << endl;
break;
}
if (points < LOSE_POINTS && i == MAX_ROUNDS) {
cout << "you lose! too few points." << endl;
break;
}
}
double average = static_cast<double>(points) / roundsPlayed;
cout << "\ngame over." << endl;
cout << "total points: " << points << endl;
cout << "average per round: " << average << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgbWFpbigpIHsKCWludCBwb2ludHMgPSAwOwoJaW50IHJvdW5kc1BsYXllZCA9IDA7Cgljb25zdCBpbnQgTUFYX1JPVU5EUyA9IDEwOwoJY29uc3QgaW50IFdJTl9QT0lOVFMgPSA1MDA7Cgljb25zdCBpbnQgTE9TRV9QT0lOVFMgPSAyMDA7CgkKCXNyYW5kKHRpbWUoMCkpOwoJCgljb3V0IDw8ICJzdGFydGluZyBwb2ludHM6ICIgPDwgcG9pbnRzIDw8IGVuZGw7CgkKCWZvciAoaW50IGkgPSAxOyBpPD0gTUFYX1JPVU5EUzsgaSsrKSB7CgkJaW50IHJvdW5kU2NvcmUgPSByYW5kKCkgJSAxMDE7CgkJcG9pbnRzICs9IHJvdW5kU2NvcmU7CgkJcm91bmRzUGxheWVkKys7CgkJCgkJY291dCA8PCAicm91bmQgIiA8PCBpIDw8ICI6IHNjb3JlZCAiIDw8IHJvdW5kU2NvcmUgPDwgIiBwb2ludHMsIHRvdGFsID0gIiAKCQkgICAgIDw8IHBvaW50cyA8PCBlbmRsOwoJCSAgICAgCgkJICAgICBpZiAocG9pbnRzID49IFdJTl9QT0lOVFMpIHsKCQkgICAgIAljb3V0IDw8ICJ5b3Ugd2luISB5b3UgcmVhY2hlZCAiIDw8IHBvaW50cyA8PCAiIHBvaW50cy4iIDw8IGVuZGw7CgkJICAgICAJYnJlYWs7CgkJICAgICB9CgkJICAgICAKCQkgICAgIGlmIChwb2ludHMgPCBMT1NFX1BPSU5UUyAmJiBpID09IE1BWF9ST1VORFMpIHsKCQkgICAgIAljb3V0IDw8ICJ5b3UgbG9zZSEgdG9vIGZldyBwb2ludHMuIiA8PCBlbmRsOwoJCSAgICAgCWJyZWFrOwoJCSAgICAgfQoJfQoJCglkb3VibGUgYXZlcmFnZSA9IHN0YXRpY19jYXN0PGRvdWJsZT4ocG9pbnRzKSAvIHJvdW5kc1BsYXllZDsKCQoJY291dCA8PCAiXG5nYW1lIG92ZXIuIiA8PCBlbmRsOwoJY291dCA8PCAidG90YWwgcG9pbnRzOiAiIDw8IHBvaW50cyA8PCBlbmRsOwoJY291dCA8PCAiYXZlcmFnZSBwZXIgcm91bmQ6ICIgPDwgYXZlcmFnZSA8PCBlbmRsOwoJCglyZXR1cm4gMDsKCQp9
starting points: 0
round 1: scored 35 points, total = 35
round 2: scored 90 points, total = 125
round 3: scored 84 points, total = 209
round 4: scored 27 points, total = 236
round 5: scored 14 points, total = 250
round 6: scored 55 points, total = 305
round 7: scored 91 points, total = 396
round 8: scored 87 points, total = 483
round 9: scored 98 points, total = 581
you win! you reached 581 points.
game over.
total points: 581
average per round: 64.5556