c语言可编译无法组建,c语言入门经典 的代码在ubunut下可以编译却无法正确运行...

求助 c语言入门经典 的代码在ubunut下可以编译却无法正确运行!

第四章最后设计的那个程序,有两个问题,一个根本没有打印随机数,第二个主体循环无效,也就是没有要求输入(Y/N),直接执行return 0了.

请问这是什么问题啊?

/* Program 4.12 Simple Simon */

#include                      /* For input and output   */

#include                      /* For toupper() function */

#include                    /* For bool, true, false  */

#include                     /* For rand() and srand() */

#include                       /* For time() and clock() */

int main(void)

{

/* Records if another game is to be played */

char another_game = 'Y';

/* true if correct sequence entered, false otherwise */

int correct = false;

/* Number of sequences entered successfully          */

int counter = 0;

int sequence_length = 0;     /* Number of digits in a sequence        */

time_t seed = 0;             /* Seed value for random number sequence */

int number = 0;              /* Stores an input digit                 */

time_t now = 0;            /* Stores current time - seed for random values  */

int time_taken = 0;        /* Time taken for game in seconds                */

/* Describe how the game is played */

printf("\nTo play Simple Simon, ");

printf("watch the screen for a sequence of digits.");

printf("\nWatch carefully, as the digits are only displayed"

" for a second! ");

printf("\nThe computer will remove them, and then prompt you ");

printf("to enter the same sequence.");

printf("\nWhen you do, you must put spaces between the digits. \n");

printf("\nGood Luck!\nPress Enter to play\n");

scanf("%c", &another_game);

/* One outer loop iteration is one game */

do

{

correct = true;         /* By default indicates correct sequence entered */

counter = 0;            /* Initialize count of number of successful tries*/

sequence_length = 2;    /* Initial length of a digit sequence            */

time_taken = clock();  /* Record current time at start of game       */

/* Inner loop continues as long as sequences are entered correctly */

while(correct)

{

/* On every third successful try, increase the sequence length */

sequence_length += counter++%3 == 0;

/* Set seed to be the number of seconds since Jan 1,1970  */

seed = time(NULL);

now = clock();                  /* record start time for sequence  */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值