RSS
 

C 语言 之 猜数字

29 Jul

昨天晚上无聊写的,很简单。其实也没什么目的,只是觉得应该实现出来什么东西。然后也没有大的能力,就写了这么个东西出来,练了几个函数的用法。

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

main()
{
	int c,i,j,flag;

	time_t timep;
	time(&timep);

	printf("Hello, user, %s, welcome!\t\tCurrent time is %s\nLet our game begin.\n",cuserid(),asctime(gmtime(&timep)));

	while((c=getchar())!=EOF){
		i = 1 + (int) ( 10.0 * rand()/(RAND_MAX + 1.0));

		while(flag){

			printf("Just Guess The Number:\t");
			scanf("%d",&j);
			if (i == j){
				printf("Bingo!");
				break;
				flag = 0;
			}
			else
				printf("No...");
		}
			printf("\nYeah! This time is %d!\nHere we go again~ If you wanna quit, just simply type Ctrl + Z\n",i);

	}
}

就是这个了,其实自己也觉得有点白痴,anyway 就是记录在这里~ have fun

 
2 Comments

Posted in web

 

Tags: , , , ,

Leave a Reply

 
Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).
 
  1. 1024

    July 30, 2008 at 12:10 am

    建议告诉用户太大了还是太小了,直至猜对为止,然后告诉他“你猜了n次才猜对”,如果n>5就说你太笨了,如果n<3就是你很聪明之类的。那样就更好玩了。也显得很智能的样子。

    ReplyReply
     
  2. 柒小诺

    July 30, 2008 at 1:22 am

    我想这个问题来着,但是我的想法是创立一个文件,里面包含着一些话。然后随机的出现,就跟魔兽里那些单位说话一样的,但是文件读取这个事情我还比较不明白……努力中~~~

    ReplyReply