随机数程序 [英] random number program
本文介绍了随机数程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我正在编写一个非常简单的C ++程序来测试随机数调用,但是代码编译并运行它似乎并不能很好地工作......看看这段代码:
i am writing a very simple C++ program to test random number recall but the code compiles and runs it just doesn't seem to work terribly well... have a look at this code:
// chunking.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i, j, num;
char s[80], s2[80];
while (1) {
num = 0;
for (i = 0; i < 10; i++) {
j = (rand() * 10) / RAND_MAX;
if (j == 10) --j;
s[i] = j+'0';
}
s[i] = 0;
printf("%s", s);
getchar();
for (j = 0; j < 100; j++)
printf("\n");
printf("Enter number: ");
scanf_s("%79s", s2);
if (!strcmp(s, s2))
printf("Incorrect!\n");
else
printf("Correct!\n");
getchar();
}
}
希望你能提供帮助!
hope you can help!
推荐答案
首先查看编译器的所有警告并修复它们。
将警告级别设置为4通常也是一个好主意。
- Wayne
Start by looking at any and all warnings from the compiler and fixing them.
Setting Warning Level to 4 is also usually a good idea.
- Wayne
这篇关于随机数程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文