回 帖 发 新 帖 刷新版面

主题:编译没错,为什么老运行部了

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{int red[33],blue[16],num1=6,num2=1,max_mid1=33,max_mid2=16,i,j;
int chosered[6],choseblue,choice_r,choice_b;
char ch1,ch2;
printf("**********欢迎购买中国福利彩票------双色球**************\n");
printf("~~~~奉献一份爱心,收获一份意外的喜悦,祝你好运!~~~~~~~~~~~~~~\n" );
printf("          您是否采用机选(y/n):");
scanf("%c",ch1); 
  if(toupper(ch1)=='Y')
    {do
       { for(i=0;i<max_mid1;i++)   /*所有的红球*/ 
             {
              red[i]=i+1;
                }
         srand((unsigned)time(NULL));  /*随机取出6红球*/ 
         for(i=0;i<num1;i++)
           {choice_r=rand()%max_mid1;
             chosered[i]=red[choice_r];
             for(j=choice_r;j<max_mid1;j++)
               {red[j]=red[j+1];
                  }
              max_mid1--;  
            } 
         for(i=0;i<max_mid2;i++)  /*所有的蓝球*/ 
           {
              blue[i]=i+1;  
            } 
          srand((unsigned)time(NULL));  /*随机取出1蓝球*/ 
          choice_b=rand()%max_mid2;
          choseblue=blue[choice_b];
          printf("本注双色球机选的号码为:"); /*号码输出*/ 
          printf("红球为:");
          for(i=0;i<num1;i++)
            {printf("   %d",chosered[i]);
             }
          printf("   蓝球为:%d",choseblue); 
          printf("是否再选一注(y/n)");
          scanf("%c",ch2);
    }while(toupper(ch2)=='Y');
   } 
 else 
 {printf("请输入你所选的号码");
 } 
 getch();
 return 0;
}    
       
       

回复列表 (共6个回复)

沙发

你用scanf接受数据的时候应该是scanf("%c",&ch2);两处都要改的!

板凳


#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
    int red[33],blue[16],num1=6,num2=1,max_mid1=33,max_mid2=16,i,j;
    int chosered[6],choseblue,choice_r,choice_b;
    char ch1,ch2;
    printf("**********欢迎购买中国福利彩票------双色球**************\n");
    printf("~~~~奉献一份爱心,收获一份意外的喜悦,祝你好运!~~~~~~~~~~~~~~\n" );
    printf("          您是否采用机选(y/n):");
    [color=FF00FF]scanf("%c",&ch1);[/color]
    if (toupper(ch1)=='Y')
    {
        do
        {
            for (i=0;i<max_mid1;i++)  /*所有的红球*/
            {
                red[i]=i+1;
            }
            srand((unsigned)time(NULL));  /*随机取出6红球*/
            for (i=0;i<num1;i++)
            {
                choice_r=rand()%max_mid1;
                chosered[i]=red[choice_r];
                for (j=choice_r;j<max_mid1;j++)
                {
                    red[j]=red[j+1];
                }
                max_mid1--;
            }
            for (i=0;i<max_mid2;i++) /*所有的蓝球*/
            {
                blue[i]=i+1;
            }
            srand((unsigned)time(NULL));  /*随机取出1蓝球*/
            choice_b=rand()%max_mid2;
            choseblue=blue[choice_b];
            printf("本注双色球机选的号码为:"); /*号码输出*/
            printf("红球为:");
            for (i=0;i<num1;i++)
            {
                printf("   %d",chosered[i]);
            }
            printf("   蓝球为:%d",choseblue);
            printf("是否再选一注(y/n)");
            [color=FF0000]scanf("%c",&ch2);[/color]        }
        while (toupper(ch2)=='Y');
    }
    else
    {
        printf("请输入你所选的号码");
    }
    getch();
    return 0;
}

3 楼


xie xie

4 楼


为什么循环不行啊

5 楼

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
    int red[33],blue[16],num1=6,num2=1,max_mid1=33,max_mid2=16,i,j;
    int chosered[6],choseblue,choice_r,choice_b;
    char ch1,ch2;

    printf("**********欢迎购买中国福利彩票------双色球**************\n");
    printf("~~~~奉献一份爱心,收获一份意外的喜悦,祝你好运!~~~~~~~~~~~~~~\n" );
    printf("          您是否采用机选(y/n):");
    scanf("%c",&ch1);
    if (toupper(ch1)=='Y')
    {
        do
           {
            printf("机选开始\n");
            for (i=0;i<max_mid1;i++)  /*所有的红球*/
            {
                red[i]=i+1;
            }
            srand((unsigned)time(NULL));  /*随机取出6红球*/
            for (i=0;i<num1;i++)
            {
                choice_r=rand()%max_mid1;
                chosered[i]=red[choice_r];
                for (j=choice_r;j<max_mid1;j++)
                {
                    red[j]=red[j+1];
                }
                max_mid1--;
            }
            for (i=0;i<max_mid2;i++) /*所有的蓝球*/
            {
                blue[i]=i+1;
            }
            srand((unsigned)time(NULL));  /*随机取出1蓝球*/
            choice_b=rand()%max_mid2;
            choseblue=blue[choice_b];
            printf("本注双色球机选的号码为:"); /*号码输出*/
            printf("红球为:");
            for (i=0;i<num1;i++)
            {
                printf("   %d",chosered[i]);
            }
            printf("   蓝球为:%d",choseblue);
            printf("\n是否再选一注(y/n)");   
            fflush(stdin);   
            scanf("%c",&ch2);
           }while(toupper(ch2)=='Y');
    }
    else
    {
        printf("请输入你所选的号码");
    }
    getch();
    return 0;
}

再次输入要刷新缓冲区
现在循环可以运行

6 楼

你好.我是全职网赚工作者.
如果你有时间有电脑.
想在网络上创业.请联系我..
项目绝对真实.详情QQ空间资料
加盟请联系 QQ908889846

我来回复

您尚未登录,请登录后再回复。点此登录或注册