Advertisement
Spocoman

Game Number Wars

Sep 20th, 2023 (edited)
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string player1, player2, command;
  8.     cin >> player1 >> player2;
  9.     cin.ignore();
  10.     getline(cin, command);
  11.  
  12.     int card1, card2, point1 = 0, point2 = 0;
  13.  
  14.     while (command != "End of game") {
  15.         card1 = stoi(command);
  16.         cin >> card2;
  17.  
  18.         if (card1 > card2) {
  19.             point1 += card1 - card2;
  20.         }
  21.         else if (card1 < card2) {
  22.             point2 += card2 - card1;
  23.         }
  24.         else {
  25.             cin >> card1 >> card2;
  26.  
  27.             cout << "Number wars!\n";
  28.  
  29.             if (card1 > card2){
  30.                 cout << player1 << " is winner with " << point1 << " points\n";
  31.             }
  32.             else {
  33.                 cout << player2 << " is winner with " << point2 << " points\n";
  34.             }
  35.             break;
  36.         }
  37.         cin.ignore();
  38.         getline(cin, command);
  39.     }
  40.  
  41.     if (command == "End of game") {
  42.         cout << player1 << " has " << point1 << " points\n"
  43.             << player2 << " has " << point2 << " points\n";
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement