發新話題

[問題] 急! c++ 寫翻轉硬幣的程式

急! c++ 寫翻轉硬幣的程式

Write a program that flips a coin four times in a row. Every four consecutive flips is countedas one trial​. The program will use the random function​to decide if the flip results in head ortail. Starting by prompting the user for the number of trials and the seed for the random function.If the four consecutive flipping results are all heads (successful trial) then the program returnsthe count of the trial. Return indication when the program reach the maximum number of trialswithout the successful trial. Use recursion​to continuously flip the coin until the successful trialor reaching the maximum number of trials without successful trial. Display the result of eachtrail. Use the pseudocode below as the template for one sample code

下面是老師給的模板

# include <iostream>
# include <...>
using namespace std;
enum coinFace {head = 1, tail}; // global enumerated variable
void coinToss();
int main() {
unsigned seed; int trials;
//prompt for input of trials and seed
srand(seed); //set seed for random generator
//call coinToss() function
return 0;
}
void coinToss() {
//use FOR loop to toss the coin 4 times
//use array to save the results of the flips
// display the result of each trial
if (successful run)
// return the number of trial
else if (reaching max trials without successful run)
// return indication
else //use recursion to recall the coinToss() fuction
}

最後可以再跟我解釋一下怎麼做嗎 謝謝!

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。