//用隨機(jī)數(shù)函數(shù)來(lái)模擬硬幣投擲即可,即rand() % 2即可以得到1或者0.
//VC6,xp系統(tǒng)
#include
#include
using namespace std;
int toss();
int main(void)
{
\x05int head,tail,total,num,temp,cnt;
\x05cout
c++ 硬幣正反面問(wèn)題
c++ 硬幣正反面問(wèn)題
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.
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.
其他人氣:706 ℃時(shí)間:2020-03-29 04:21:43
優(yōu)質(zhì)解答
我來(lái)回答
類(lèi)似推薦
- 硬幣正反面的概率問(wèn)題
- 1圓硬幣正反面的幾率是多少?
- 投硬幣十次正反面各五次的幾率
- 陳蕃的“蕃”在這里的讀音是什么?
- But the one million people of the city,who thought little of these events,were asleep as usual that
- 線粒體的氧化磷酸化和葉綠體的光合磷酸化有什么共同點(diǎn)和不同點(diǎn)?
- 一個(gè)含30度角的直角三角形能否分割成2個(gè)全等的三角形
- 設(shè)f(x)=√x,g(x)=-x+a(a>0,a∈R),若不等式▏{f(x)+a[g(x)-2a]}/f(x)▕ ≤1對(duì)x∈[1,4]恒成立,求a的取值范圍.小弟拜謝!
- 熱帶魚(yú)最適合的溫度是幾度?
- 有關(guān)圓周率的知識(shí)
- f(x)=|x²+3x|,關(guān)于x的方程f(x)-a|x-1|=0恰有4個(gè)互異的實(shí)根,則a的取值范圍
- 在下列敘述中,能說(shuō)明鹽酸是強(qiáng)酸,醋酸是弱酸的是( )
猜你喜歡
- 1用120個(gè)邊長(zhǎng)是1cm的正方形,可以擺出 種面積是120平方厘米的長(zhǎng)方形.
- 2m為何值時(shí),方程組y=x+my2?4x?2y+1=0 (1)有兩組不相等的實(shí)數(shù)解; (2)有相同的兩組實(shí)數(shù)解; (3)無(wú)實(shí)數(shù)解.
- 3初一語(yǔ)文(下)主要復(fù)習(xí)什么?
- 4腦筋急轉(zhuǎn)彎:.How can you make a rope shorter without cutting or winding it?
- 5一根跳繩長(zhǎng)五分之四米,這根跳繩的四分之三有多長(zhǎng)?怎么算?
- 6人們?cè)诖笞匀恢惺艿竭^(guò)哪些啟發(fā),有什么發(fā)明創(chuàng)造
- 7為什么before后面加being given而不是giving
- 8不要把污水直接排入河流英文怎么說(shuō)
- 9兩個(gè)同體積的容器一個(gè)裝HCl氣體另一裝H2和CL2的混合氣體同溫同壓下,一定相同的是.
- 10五星村共有小麥的320公頃,玉米地比小麥地多1/4,這個(gè)村的玉米地比小麥地多多少公頃?玉米地有多少公頃?
- 11老外口中的的she average是什么意思
- 12大什么大什么,要成語(yǔ)的.