自己做的一个关于彩票中奖率的计算代码

name61 2008-03-04 11:57:35
#include <iostream>
using namespace std;

long double probability(unsigned numbers, unsigned picks);

int main()
{
double total1, choices, total2;
double probability1, probability2;
cout<<"Enter the total number of choices on the game card and\n"//输入第一个选区
"the number of picks allowed:\n";
while ((cin>>total1>>choices)&&choices<=total1)
{
cout<<"Enter total number of game card choices for the mege number:\n";//第二个..
if (!(cin>>total2))
break;
probability1=probability(total1, choices);
probability2=probability(total2, 1);
cout<<"You have one chance in "<<probability1*probability2<<"of winning.\n";
cout<<"Enter the total number of choices on the game card and\n"
"the number of picks allowed again:\n";
}
cout<<"Bye.\n";
return 0;
}
long double probability(unsigned numbers, unsigned picks)//计算中奖率
{
long double result=1.0;
long double n;
unsigned p;
for (n = numbers, p = picks; p>0; n--,p--)
result = result*n/p;
return result;
}
...全文
275 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaymin 2008-03-05
  • 打赏
  • 举报
回复
楼主请注意一下代码的格式
name61 2008-03-05
  • 打赏
  • 举报
回复
恩,明白了
我也觉得这样有问题
name61 2008-03-04
  • 打赏
  • 举报
回复
哈哈,跟大家分享下我的一个小的劳动成果

64,849

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧