[問題] 有關function引出引入問題,以及dowhile …
在寫一個程式,是有關於猜數字的小程式
因為是初學...所以function的引出引入值一直有問題...
以致不斷的有bug出現,主體使用dowhile迴圈設定打算再call ab時
引入x的值也就是4A時,導入while內就能結束
不過目前一直慘烈失敗阿...........囧
能否拜託各位高手解救,在這邊先謝謝大家了
以下附上原始碼:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
//#define
int ab(x);
int main(void)
{
        int i=1,real[4]={0,1,2,3},test[4];
   do{
     if(i>10)
          {printf("你輸了,處罰是今天回家要洗碗!!");
          break;}
    printf("請輸入4個介於0~9之間的數字,不可重複:\n");
    test[0]=getch();
    putchar(test[0]);
    test[1]=getch();
    putchar(test[1]);
    if(test[1]==test[0])
      {printf("不可重複\n");
      continue;}
    test[2]=getch();
    putchar(test[2]);
    if(test[2]==test[0]||test[2]==test[1])
      {printf("不可重複\n");
      continue;}
    test[3]=getch();
    putchar(test[3]);
    if(test[3]==test[0]||test[3]==test[1]||test[3]==test[2])
      {printf("不可重複\n");
      continue;}
    ab(x);
    printf("這是第%d次嘗試\n",i);
    i++;
   }while(x!=4);
   system("pause");
   return 0;
}
int ab(int test[4],int real[4])
{
    int w,z,x=0,y=0;
    for(w=0;w<4;W++)
     for(z=0;z<4;Z++)
      if(real[w]==test[z])
       if( w == z )
        x++;
       else
        y++;
    printf(" %d A %d B",x,y);
     if(x==4)
     printf("you win!!");
    return x;
 }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.137.76.153
※ 編輯: sleepgogo       來自: 220.137.76.153       (02/12 22:22)
→
02/12 22:40, , 1F
02/12 22:40, 1F
→
02/12 22:42, , 2F
02/12 22:42, 2F
→
02/12 22:46, , 3F
02/12 22:46, 3F
→
02/12 22:59, , 4F
02/12 22:59, 4F
→
02/12 23:00, , 5F
02/12 23:00, 5F
→
02/12 23:00, , 6F
02/12 23:00, 6F
→
02/12 23:01, , 7F
02/12 23:01, 7F
→
02/12 23:02, , 8F
02/12 23:02, 8F
→
02/12 23:04, , 9F
02/12 23:04, 9F
→
02/12 23:04, , 10F
02/12 23:04, 10F
→
02/12 23:05, , 11F
02/12 23:05, 11F
→
02/12 23:07, , 12F
02/12 23:07, 12F
→
02/12 23:17, , 13F
02/12 23:17, 13F
→
02/12 23:18, , 14F
02/12 23:18, 14F
→
02/12 23:19, , 15F
02/12 23:19, 15F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章