Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- int main()
- {
- const int div{ 2 }; // count of players to calculate turn number from i
- int drop{ 0 };
- int playerSum{ 0 };
- int computerSum{ 0 };
- char space{ ' ' };
- const int minValue{ 1 };
- const int maxValue{ 6 };
- bool comp{ false }; // who roll the dice: true - comp, false - human :)
- srand(time(0));
- std::cout << "\t\t\"The Dice\"\n\nOne by one we will roll the dice,\none, who will have the biggest sum\nin three rolls will win!!!\n\t\tGood luck!!!\n\n";
- for (int i{ 1 }; i <= 6; comp = !comp, ++i)
- {
- std::cout << (comp ? "My " : "You ") << "roll No." << ((i / div) + (i % div)) << "\nPress \"" << (comp ? 'c' : 'd') << "\" to roll the dice ---> ";
- std::cin >> space;
- while (space != (comp ? 'c' : 'd'))
- {
- std::cout << "Oops, wrong key! Try again ---> ";
- std::cin >> space;
- }
- for (int i{ 0 }; i < 2; ++i)
- {
- drop = rand() % maxValue + minValue;
- std::cout << "* * * * *\n";
- if (drop == 1) { std::cout << "* *\n* # *\n* *\n"; }
- else if (drop == 2) { std::cout << "* # *\n* *\n* # *\n"; }
- else if (drop == 3) { std::cout << "* # *\n* # *\n* # *\n"; }
- else if (drop == 4) { std::cout << "* # # *\n* *\n* # # *\n"; }
- else if (drop == 5) { std::cout << "* # # *\n* # *\n* # # *\n"; }
- else if (drop == 6) { std::cout << "* # # *\n* # # *\n* # # *\n"; }
- std::cout << "* * * * *\n\n";
- comp ? computerSum += drop : playerSum += drop;
- }
- std::cout << (comp ? "My " : "You ") << "score is " << (comp ? computerSum : playerSum) << "\n\n";
- }
- if (playerSum > computerSum)
- {
- std::cout << "Congratulations!!! You are the winner!! You have " << playerSum << " while I have just " << computerSum << "\n\n";
- }
- else if (playerSum < computerSum)
- {
- std::cout << "I'm sorry =( I am the winner!! You have just " << playerSum << " while I have " << computerSum << "\n\n";
- }
- else
- {
- std::cout << "Today it's draw!! Congrats! We both have " << playerSum << "\n\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment