【发布时间】:2016-01-09 15:06:26
【问题描述】:
我需要创建一个模拟彩票的程序。我已经生成了开奖号码和彩票,还让用户输入了奖金。我的问题是,如何将门票打印到记事本文件中?我已经用谷歌搜索了几个小时,找不到任何东西。附件是我到目前为止所做的代码。提前致谢。
int draw = 4, i, money; //for drawn numbers and prize money
int n = 5, j, x, y = 10; //for generating tickets
bool arr[100] = { 0 };
time_t t;
printf("The Prize money to be won is $ ");
scanf_s("%d", &money);
printf("\n\nThe 4 drawn Numbers are: \n");
srand((unsigned)time(&t));
for (i = 0; i < draw; ++i)
{
int r = rand() % 25;
if (!arr[r])
printf("%3d ", r + 1);
}
printf("\n");
// generate tickets
printf("\n\nThe tickets are:\n");
srand((unsigned)time(&t));
for (x = 0; x < y; ++x)
{
for (j = 0; j < n; ++j)
{
int r = rand() % 25;
if (!arr[r])
printf("%3d ", r + 1);
}
printf("\n");
}
return 0;
【问题讨论】:
-
检查
scanf()是否为scanf_s("%d", &money);返回1。 -
哦,没有记事本文件,你要的是文本文件。
-
Write to .txt file?的可能重复
-
notepad文件只不过是一个文本文件,没有特殊格式。 -
希望贴出的代码在
main()函数内,并且该函数以#include <stdio.h>和#include <stdlib.h>为前缀
标签: c