| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 901 人关注过本帖
标题:程序中用到了随机函数,头文件加了#include 编译时还是说random没定义
只看楼主 加入收藏
SUN21
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-9-25
收藏
 问题点数:0 回复次数:0 
程序中用到了随机函数,头文件加了#include 编译时还是说random没定义

程序中用到了随机函数,头文件加了#include <stdlib.h> 编译时还是说 random,randomize没定义
不知怎么回事,程序如下:


#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>

void myplus() ; //产生加法题
void myminus() ; //产生减法题


void myplus() {
int x ;
int y ;
int answer ;
randomize() ; //为随机函数提供不同的种子
x = random(100) ; //产生随机数
y = random(100) ;
printf("%d + %d = ?" , x,y) ;
scanf("%d" , &answer) ;
if ( answer == x+y )
printf("Great! You are clever!") ;
else
printf("You are wrong!") ;
getch() ; //等待输入,起暂停运行的作用
}

void myminus() {
int x ;
int y ;
int answer ;
randomize() ; //为随机函数提供不同的种子
x = random(100) ;
y = random(100) ;
printf("%d - %d = ?" , x,y) ;
scanf("%d" , &answer) ;
if ( answer == x-y )
printf("Great! You are clever!") ;
else
printf("You are wrong!") ;
getch() ; //等待输入,起暂停运行的作用
}

int main(int argc, char* argv[])
{
myplus() ;
myplus() ;
myminus() ;
myminus() ;
return 0 ;
}

搜索更多相关主题的帖子: 头文件 include 程序中 random 随机函数 
2007-10-10 14:26
快速回复:程序中用到了随机函数,头文件加了#include 编译时还是说random没定义 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011027 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved