注意:在C语言中,变量必须声明在函数开始的地方
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#define true 1
#define false 0
int main(){
char another_game ='Y' ;
int correct = false;
int counter = 0 ;
int sequence_length = 0 ;
time_t seed = 0 ;
int number = 0 ;
time_t now = 0 ;
int time_taken = 0 ;
int i =0;
printf(" \n To play Simple Simon ,");
printf(" \n Watch carefully ,sa the digits are only displayed for a second !");
printf(" \n the computer will remove them , and then prompt you ");
printf(" to enter the same sequence.");
printf(" \n When you do , you must put spaces between the digits.\n");
printf(" \n GOOD lUCK !\n Press Enter to play \n");
scanf("%C",&another_game);
do{
correct = true ;
counter = 0;
sequence_length = 2 ;
time_taken = clock();
while(correct){
sequence_length += counter++% 3 == 0 ;
seed = time(NULL);
now = clock();
srand((unsigned int)seed);
//i要在开始的时候声明,在此int i = 0 ; 是不对的
for( i = 1 ; i <= sequence_length ; i ++)
{
printf("%d",rand() % 10);
}
for(;clock() - now <CLOCKS_PER_SEC;);
printf("\r");
for( i =0 ;i <= sequence_length ; i++){
printf(" ");
}
if(counter == 1){
printf("\n Now you enter the sequence - don't forget"
" the spaces \n ");
}else{
printf("\r");
}
srand((unsigned int)seed);
for(i = 1 ; i <= sequence_length ; i++){
scanf("%d",&number);
if(number != rand() %10){
correct = false ;
break ;
}
}
printf("%s \n",correct ? "Correct!":"Wrong!");
}
time_taken = (clock() - time_taken);
printf("\n\n Your score is %d",--counter * 100 / time_taken);
fflush(stdin);
printf("\n DO you want to play again (y/n)? ");
scanf("%c",&another_game);
}while(toupper(another_game) == 'Y' );
return 0 ;
}
发表评论
-
课后习题4.3
2011-10-18 21:29 673/*Exercise 4.3 Displaying print ... -
课后习题4.2
2011-10-18 19:34 563/* isgraph();判断字符c是否为除空格外的可打印字符 ... -
课后习题4.1
2011-10-18 19:11 619/*输入程序实现乘法表*/ #include<stdi ... -
学习笔记习题3.4:goto 用法
2011-10-15 19:15 710#include<stdio.h> int ma ... -
学习笔记习题3.3
2011-10-14 00:34 833#include<stdio.h> #defin ... -
学习笔记习题3.2
2011-10-14 00:19 561#include<stdio.h> int ma ... -
第三章 例子
2011-10-13 21:51 613#include<stdio.h> int ma ... -
学习笔记习题2.3
2011-10-11 21:10 856/* programe exercise 2.3 */ #i ... -
C语言入门经典
2011-10-10 23:17 600/* programe which rember user ... -
学习笔记
2011-10-10 22:49 514/*write a programe,rember user ... -
rhel6.1 server 安装amule
2011-06-17 19:51 1250在rhel6.1下安装amule2.2.6 1、安装wxWi ... -
rhel6.1 server 安装transmission
2011-06-16 22:16 1143不知道什么原因,在rhel server6.1上安装trans ... -
jsp页面跳转方法——转自互联网
2010-04-09 21:21 8171. RequestDispatcher.forward() ... -
各种实用小技巧
2010-03-22 17:01 7381.动态生成button ... -
成长之路 之servlet读取数据库数据 输出为XML时的乱码问题:
2010-03-19 15:50 1023servlet读取数据库数据 输出为XML时的乱码问题: 恩 ...
相关推荐
abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit ...
2.17 do/while重复结构 2.18 break和continue语句 2.19 逻辑运算符 2.20 混淆相等(.==)与赋值(=)运算符 2.21 结构化编程小结 2.22 有关对象的思考:确定问题中的对象 小结 术语 自测练习 自测练习答案 ...
2.17 do/while重复结构 2.18 break和continue语句 2.19 逻辑运算符 2.20 混淆相等(.==)与赋值(=)运算符 2.21 结构化编程小结 2.22 有关对象的思考:确定问题中的对象 小结 术语 自测练习 自测练习答案 ...
息循环等。 HGE 架构在DirectX 8.0 之上,能够跑在大多数的Windows 系统上。 1. 选用HGE 的理由: 1)专业化--- 专注于2D 领域 2)简单化--- 非常容易使用 3)技术优势--- 基于Direct3D API 有较好的性能和特性 4)...
Bool型(true/false) DataTime datExample; 日期型("09/19/2002") int intExample; 整数(32位有符号整数) double dblExample; 浮点数(64位双精度浮点数) 二、各种运算: = 赋值运算 + 加法运算 - 减法运算 * 乘法...
下面的伪代码演示了消息循环的用法: while(1) { id=getMessage(...); if(id == quit) break; translateMessage(...); } 当该程序没有消息通知时getMessage就不会返回,也就不会占用系统的CPU时间。 下图为...
迭代语句do, for, foreach, in, while 跳转语句break, continue, default, goto, return 异常处理语句throw, try-catch, try-finally Checked 和 Uncheckedchecked, unchecked fixed 语句Fixed lock 语句Lock (1) ...
1.8,do、while、for关键字......................................... 28 1.8.1,break与 continue的区别...........................28 1.8.2,循环语句的注意点.....................................29 1.9,...
1.8,do、while、for 关键字................................................................................................... 28 1.8.1,break 与continue 的区别............................................
1.8,do、while、for 关键字................................................................................................... 28 1.8.1,break 与continue 的区别............................................
1.8,do、while、for 关键字................................................................................................... 28 1.8.1,break 与continue 的区别............................................
1.8,do、while、for 关键字................................................................................................... 28 1.8.1,break 与continue 的区别............................................
1.8,do、while、for 关键字................................................................................................... 28 1.8.1,break 与 continue 的区别...........................................
1.8,do、while、for 关键 字............................................................................................. ...... 28 1.8.1,break 与 continue 的区 别......................................