用C语言编写程序问题,急用~

来源:百度知道 编辑:UC知道 时间:2024/06/19 13:23:51
1.编写一函数,返回1-6之间的随机数。
2.继续上一道题。编写一掷骰子游戏,计算机和用户充当对战的双方。首先由计算机生成一个随机数,然后接受用户输入的字符串“g”命令后生成用户的随机数(模拟用户掷了一次骰子),比较他们的大小,如果用户得到的随机数小于计算机得到的,则输出用户输了,否则输出用户赢了。

//VC2005 下调试通过

// Zhidao.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>

int GetRadomNumber( int lower, int upper );

int main(void)
{
//计算机产生随机数
int lower =0;
int upper = 6;
int computer=0;
int user=0;
char ch;

const char * menu= "\n请选择命令: G(产生用户随机数)\tQ(退出系统!):\t";

printf( "%s", menu );
while ( true )
{
computer = GetRadomNumber(lower, upper);
ch = getchar();
ch = tolower(ch);
getchar();

if ( ch != 'g' && ch!= 'q')
{
printf( "\n输入无效!\n%s", menu );
}
if ( ch == 'q')
{
break;
}
else
{
user = GetRadomNumber( lower, upper)