有人可以告诉我如何为此代码创建功能? [英] Can Someone Please Tell Me How I Can Create Fuction For This Code ?
本文介绍了有人可以告诉我如何为此代码创建功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
#include<stdlib.h>
#include<time.h>
int main()
{
int x;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
x = rand() % 6 +1 ;
printf("random number %d \n ", x);
return 0;
}
推荐答案
您已经拥有:main
是一个函数。
如果你想移动
You already have:main
is a function.
if you are trying to move
x = rand() % 6 +1 ;
进入一个单独的函数,然后试试这个:
into a separate function, then try this:
int GetRandomNumber()
{
return rand() % 6 + 1;
}
int main()
{
int x;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
x = GetRandomNumber();
printf("random number %d \n ", x);
return 0;
}
这篇关于有人可以告诉我如何为此代码创建功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文