题目
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.
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.
提问时间:2021-04-01
答案
//用随机数函数来模拟硬币投掷即可,即rand() % 2即可以得到1或者0.
//VC6,xp系统
#include
#include
using namespace std;
int toss();
int main(void)
{
x05int head,tail,total,num,temp,cnt;
x05cout
//VC6,xp系统
#include
#include
using namespace std;
int toss();
int main(void)
{
x05int head,tail,total,num,temp,cnt;
x05cout
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1田园乐 其六 在写景方面运用了什么表现手法
- 2一个林场前年植树1480课,去年植树的棵树是前年的2倍,今年植树的棵树比前两年植树的总数还多420课,
- 3非匀速圆周运动中向心力是否由合力提供 还有请详细解释一下这道题中向心力究竟是什么 ,一半径为R的光滑绝缘圆环竖直固定在水平桌面上,桌面所在空间有水平向右的匀强电场,电场强度为E.在此圆环上套着一个质量
- 4应用题甲乙两车同时同地出发去同一目的地,甲车每小时行40千米,乙车每小时行35
- 5作文:那一刻我长大了,怎么写
- 6关于现代孝心的事例
- 71.一量筒中盛有水,水面刻度是180ml,把体积80cm^3的木块放进量筒的水里,静止时水面升到230ml,.
- 8已知函数y=x负二次方(1)它是奇函数还是偶函数+(2)它的图像具有怎样的对称性(3)它在(0,正无穷大)上%D%A
- 9屋顶的面积是45m2,大气对屋顶的压力有多大?这么大的压力为什么没有把屋顶压塌呢?
- 10句子“一旦超过森林可承载的限度”中的承载的近义词是什么?
热门考点