Advertisement
Spocoman

Darts Tournament

Oct 6th, 2023 (edited)
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int startPoints, points;
  9.     cin >> startPoints;
  10.     cin.ignore();
  11.  
  12.     int moves = 0;
  13.  
  14.     while (startPoints > 0) {
  15.         string command;
  16.         getline(cin, command);
  17.         moves++;
  18.  
  19.         if (command == "bullseye") {
  20.             break;
  21.         }
  22.  
  23.         cin >> points;
  24.         cin.ignore();
  25.  
  26.         if (command == "double ring") {
  27.             points *= 2;
  28.         }
  29.         else if (command == "triple ring") {
  30.             points *= 3;
  31.         }
  32.  
  33.         startPoints -= points;
  34.     }
  35.  
  36.     if (startPoints == 0) {
  37.         cout << "Congratulations! You won the game in " << moves << " moves!\n";
  38.     }
  39.     else if (startPoints < 0) {
  40.         cout << "Sorry, you lost. Score difference: " << abs(startPoints) << ".\n";
  41.     }
  42.     else {
  43.         cout << "Congratulations! You won the game with a bullseye in " << moves << " moves!\n";
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement