Request input from user is simply
cout <<'Request>> ";
cin >> variable;
but what do you mean switch back to the computer? How is the computer supposed to generate an input?
But as far as do-while, I would reccommend using this only if you are certain that the code you are including inside the do needs to be executed at least once in all cases.
If every human action is followed by an action by the computer, simply put them both sequentially in your loop:
1 2 3 4 5
while (!stop) {
// Human actions
// Computer actions
}
However, if that guarantee is not given (e.g. the game can quit after the human player's turn, thus skipping the computer's turn), you can use a control variable:
1 2 3 4 5 6 7 8 9 10
bool human_turn = true; // Human player begins
while (!stop) {
if (human_turn) {
// Human actions
}
else {
// Computer actions
}
human_turn = !human_turn;
}
do{
cout <<"Group? >>"
cin >> grpSel // a char varaible
cout << "How many?>> "
cin >> takeSel // an int variable
/*
An if else conditional to take 'takeSel' from selected group
*/
// computer part
srand(time(NULL)); // seed the RNG with current time from Jan 1 1970, different on each
// execution.
int rng1=rand()%100;
int rng2= rand()%3 // or any other type of operation you like
if (rng1>=50) { grpSel=='B' // or A your choice};
else {grpSel=='A' // or v.v.}
/* Some modifier of rng2 to get a number between 0 and the max you want the computer to take and then the following operations for the taken numbers */
// change of the terminating test here. [i.e. sentinel value not reached etc.]
}while('terminating test')// the test need be included so that the game stops when the
// conditions you define are reached
stop is a boolian variable initialized to false. You would need a statement in the while loop to check it after each turn, to see if the stop condition is reached. the ! is the not operator and produces the opposite of the variable inquestion[ i.e. if var=true then !var = false, if var=false then !var=true]
[in case you need it ->
declaring stop:
bool stop=false; ]