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

#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;
}
...全文
228 3 打赏 收藏 举报

3 条回复

jaymin 2008-03-05
• 打赏
• 举报

name61 2008-03-05
• 打赏
• 举报

name61 2008-03-04
• 打赏
• 举报 彩票中奖率测试 彩票中奖率畅想 彩票调度算法权重分配 练习9-15：彩票中奖率分析（Python变成从入门到实践学习）
Python变成从入门到实践第二版（埃里克） 模拟刮刮乐

1. 请不要发布与C++技术无关的贴子
2. 请不要发布与技术无关的招聘、广告的帖子
3. 请尽可能的描述清楚你的问题，如果涉及到代码请尽可能的格式化一下