| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 345 人关注过本帖
标题:请教*。*
取消只看楼主 加入收藏
谢绝微笑
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-12
收藏
 问题点数:0 回复次数:1 
请教*。*
诸位大侠,请问怎样可以直接终 止一次循环从而直接进行下一次循环呢? 菜鸟咯,什么都不懂,帮帮我啦~~
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()

{
    float preparation_time,track_time,match_time,stop_time,temp;
    int rider_amount,NO,foul=0,refuse=0,stop_number=0,real_score,finish_score;
    char input='1';
    clock_t preparation,start,stop,continu,end;

    printf("Please input the number of riders:");
    rider_amount=getchar()-48;
    getchar();
    printf("The number of riders is:%d\n",rider_amount);

    for(NO=1;NO<=rider_amount;NO++)
    {
        printf("When The referee say \"start at will\", press \"a\" and then enter. \n");
        input=getchar();
        getchar();
        
        do{
           {if(input=='a'){
              preparation = clock();

              printf("When the equipage passes the start line press \"b\" and then enter\n");
              input=getchar();
              getchar();
             }
           else {printf("Wrong!");
                 printf("When The referee say \"start at will\", press \"a\" and then enter. \n");
                 input=getchar();
                 getchar();
                 };}

        }while(input=='a');

        do{
            {if(input=='b'){
              start = clock();

              preparation_time=(start - preparation) / CLK_TCK;
              printf("The preparation time was: %f\n",preparation_time );
              printf("When the equipage passes the goal line,press \"f\" and then enter\n");
              printf("If the player doesn't finish,press \"d\" \nIf the rider pulls down obstacles press \"p\"\nIf the horse refuse to jump,press \"r\"\n");
              printf("If the obstacle need repair,press \"s\"\n");
              input=getchar();
              getchar();}

            else {printf("Wrong!");
                 printf("When the equipage passes the start line press \"b\" and then enter\n");
                 input=getchar();
                 getchar();
                 };}
        }while(input=='b');



        while(input!='f'){
           while(input=='p'){
               foul++;
               printf("Finish press \"f\"\nStop press \"s\"\nRefuse jump press \"r\"\n");
               input=getchar();
               getchar();
               }

           while(input=='r'){
               foul++;
               refuse++;
               [un]if(refuse==2)return main;[/un]
               printf("Finish press \"f\"\nStop press \"s\"\nPull down press \"p\"\n");
               input=getchar();
               getchar();
               }

           if(input=='s'){
               stop=clock();
               stop_number++;
               printf("When the rider continues press \"c\"\n");
               input=getchar();
               getchar();
               do{
               if(input=='c'){continu=clock();
                  if(stop_number>1)temp=stop_time;
                  stop_time=(continu - stop) / CLK_TCK+temp;
                  printf("Stop time is %f",stop_time);
                  printf("Finish press \"f\"\nPull over press\"p\"\nRefuse press \"r\"\n");
                  input=getchar();
                  getchar();}
               else {printf("Wrong!");
                     printf("When the rider continues press \"c\"\n");
                     input=getchar();
                     getchar();
                     };
               }while(input=='c');
               }
           [un]if(input=='d')return main;[/un]           }




        if(input=='f'){
           end=clock();
           track_time=(end - start) / CLK_TCK;
           printf("The track time was: %f\n",track_time);
           match_time=track_time-stop_time;
           printf("The match time is:%f",match_time);
           };


        {
        if(match_time<=1200)finish_score=1100;
        else finish_score=1100-(match_time-1200);
        }

        {
        if(preparation_time<=45)real_score=finish_score-4*foul;
        else real_score=finish_score-4*foul-(preparation_time-45);
        }

        printf("Rider: %d\n",NO);
        printf("His score is: %d\n",real_score);
    };

}
就是在两个return main 那里,本来应该是让它进行下一次的循环的 结果搞成了直接退出程序=。=#
2008-10-12 10:46
谢绝微笑
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-10-12
收藏
得分:0 
还有咯
还有那个前面为什么rider_amount=getchar()-48;非要减去48才能等于输入的数字,虽然解决了问题,但还是想不通咯
2008-10-12 10:49
快速回复:请教*。*
数据加载中...
 
   



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

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