Solution C ++ job 03

xiaoxiao2021-03-06  115

#include #include #include #include #include usespace std;

const Int secret_size = 10; // size of secret number array const INT guess_size = 4; // size of guess number array

Void Initialize_secret (INT Secret []) {INT I; SRAND ((INT) TIME (0)); for (i = 0; i

} // USE TIME AS SEEDS

Void read_guess (int guest ") {string str; char ch; int i = 0; cout <<" guess: << endl; do {

CH = GetCh ();

IF (CH> = '0' && Ch <= '9') {PUTCHAR (CH); PUTCHAR (''); str = STR CH; I ;} // ignore other input // if (CH == 13) Cout << Endl;

} while (i <4); Guess [0] = (int) STR [0] -48; Guess [1] = (int) STR [1] -48; Guess [2] = (int) STR [2] -48; Guess [3] = (int) STR [3] -48; cout << endl;}

BOOL NO_MATCH (int SECRET [], INT guess []) {INT I, J, COWCOUNT = 0, BullCount = 0; for (i = 0; i <4; i ) {

For (j = 0; j <4; j ) {if (Secret [i] == guess [j]) {if (i == j) Bullcount ; Else Cowcount ;

Break; // Since The 4 Number Are Different;}} // end for} // end for cout << "BULL:" Bullcount << "COW: << COWCOUNT << Endl;

IF (Bullcount == 4) Return False; Else Return True;}

Void Display (Int Secret []) {INT i; for (i = 0; i <4; i ) cout << secret [i] << "; cout << endl;}

Bool Same (Int Secret []) {INT I, J; For (i = 0; I <4; i ) for (j = i 1; j <4; j ) IF (Secret [i] == Secret [ J]) Return true;}

INT main () {int secret [secRet_size]; int guest [guess_size], guesttime = 0; do {INITIALIZE_SECRET (SECRET); // Make Sure The Numbers Are Different

Cout << "Melcome to Moo !!!!!!" << endl; cout << "*********************************** *********************************** / N "" Moo is a guessing game imported from england./n "" The Computer Picks a Number Consists./n "" You Guess Four Distinct Digits Being Scored On Each Guess./N "" A / "COW /" IS A CORRECT DIGIT IN An IncorRect Position. / N "" A / "BULL /" IS A CORRECT DIGIT IN A CORRECT POSITION./N "" The Game Continues Until You Guesses All The Number. (A Score of Four Bulls) / N "" INPUT FOUR 0 to Show Secret.: ) / n "" Enioy it !!!!!! :) / n "" **************************************** ******************************** / N "<< endl; // description

Do {read_guess (guess); Guesstime ; if (Guess [0] == 0 && guess [1] == 0 && guess [2] == 0 && guess [3] == 0) Display (secret);} while (NO_MATCH (SECRET, GUESS ));

Cout << "You firmly succeed! << endl; cout <<" you have tried "<< Guesstime <<" Times! "<< endl; cout <<" Welcome to replay this game !!!!!! " << endl; return 0;}

转载请注明原文地址:https://www.9cbs.com/read-100913.html

New Post(0)