Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- /*int RandNum(int firstNum, int secondNum, int thirdNum) {
- int initialRandInt = rand() % 10;
- firstNum = initialRandInt;
- secondNum = initialRandInt;
- thirdNum = initialRandInt;
- while ( secondNum == firstNum ) {
- secondNum = rand() % 10;
- }
- while ( thirdNum == firstNum || thirdNum == secondNum ) {
- thirdNum = rand() % 10;
- }
- return firstNum, secondNum, thirdNum;
- }*/
- int main()
- {
- // Display game information and rules //
- cout << "Program: 2 MasterMind" << endl;
- cout << "The program selects 3 distinct random digits 0..9." << endl;
- cout << "On each turn you guess 3 digits. Program indicates how many are correct." << endl;
- cout << "You have 10 moves to guess the number. "
- << "Good luck!" << endl << endl;
- // setting the 3 digits with 's' or randomizing with 'r'
- cout << "Press 's' to set the three digits, or 'r' to randomize them:" << endl;
- char userInput = ' ';
- cin >> userInput;
- // setting the value of each number
- int firstNum;
- int secondNum;
- int thirdNum;
- if ( userInput == 's') {
- cin >> firstNum >> secondNum >> thirdNum;
- }
- else if ( userInput == 'r') {
- int initialRandInt = rand() % 10;
- firstNum = initialRandInt;
- secondNum = initialRandInt;
- thirdNum = initialRandInt;
- }
- while ( secondNum == firstNum ) {
- secondNum = rand() % 10;
- }
- while ( thirdNum == firstNum || thirdNum == secondNum ) {
- thirdNum = rand() % 10;
- }
- cout << "Values to guess are: " << firstNum << secondNum << thirdNum;
- cout << endl << endl << "Exiting...";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement