c++ 硬币正反面问题
c++ 硬币正反面问题
Write a program that simulates coin tossing.For each toss of the coin the program should print Heads or Tails.Let the program toss the coin a number of times as specified by the user,and count the number of times each side of the coin appears.Print the results of each toss.The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads.Note:If the program realistically simulates the coin tossing,then each side of the coin should appear approximately half the time.
The program interaction should look as follows (user inputs are in bold):
Welcome to the Coin Tossing program.
Enter the number of tosses (-1 to exit):5
Flip 1 is a:HEAD
Flip 2 is a:TAIL
Flip 3 is a:HEAD
Flip 4 is a:HEAD
Flip 5 is a:TAIL
There were 3 heads and 2 tails in 5 tosses.
Enter the number of tosses (-1 to exit):-1
Thank you for using the Coin Flipping program and have a wonderful day.
//用随机数函数来模拟硬币投掷即可,即rand() % 2即可以得到1或者0.
//VC6,xp系统
#include
#include
using namespace std;
int toss();
int main(void)
{
\x05int head,tail,total,num,temp,cnt;
\x05cout