Re: [問題] C語言猜數字問題
※ 引述《sosokill (隨便殺)》之銘言:
: do{ ←1
: srand((unsigned)time(NULL));
: for(i=0;i<10;i++)
: t[i]=-1;
: do
: { ←2
: s=rand()%9;
: if(s==t[s])
: continue;
: else
: {
: d[r]=s;
: r++;
: t[s]=s;
: }while(r<=3); ← else後面接while??
: s=0;
: do
: { ←3
: b=0;
: a=0;
: n=0;
: printf("Enter your Guess: (Press Ctrl+c to exit)\n");
: s++;
: scanf("%1d%1d%1d%1d",&g[0],&g[1],&g[2],&g[3]);
: for(i=0;i<4;i++)
: {
: if(isdigit(g[i])!=0)
: {
: printf("Please Enter Digit\n")
: continue;
: }
: }
: 1,2,3總共少了三個 "}"
: 我覺得你根本是沒有用心在檢察 最基本的"{}"都可以少這麼多個
: 還有 你有三個do 但是後面呢?do what??do you?do something?
: 另外 你排版也太亂了點 這樣不太有人會想幫你看= =
小弟曾做過的猜數字
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
int a,b,c,d,m=0,n=0,z;
char x[4];
printf("載入中...\n");
while(1){
srand(time(NULL));
a=rand()%9+1;
b=rand()%9+1;
c=rand()%9+1;
d=rand()%9+1;
if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d){
//printf("%d%d%d%d",a,b,c,d);
printf("請輸入數字\n");
while(1){
m=0;
n=0;
scanf("%s",&x);
if((int)x[0]-'0'==a){
m++;
}
else if((int)x[0]-'0'==b || (int)x[0]-'0'==c || (int)x[0]-'0'==d){
n++;
}
if((int)x[1]-'0'==b){
m++;
}
else if((int)x[1]-'0'==a || (int)x[1]-'0'==c || (int)x[1]-'0'==d){
n++;
}
if((int)x[2]-'0'==c){
m++;
}
else if((int)x[2]-'0'==a || (int)x[2]-'0'==b || (int)x[2]-'0'==d){
n++;
}
if((int)x[3]-'0'==d){
m++;
}
else if((int)x[3]-'0'==a || (int)x[3]-'0'==b || (int)x[3]-'0'==c){
n++;
}
if(m==4){
printf("%dA%dB恭喜答對!\n",m,n);
break;
}
else{
printf("%dA%dB 笨啊!~~~再試一次吧!\n",m,n);
continue;
}
}
}
else{
continue;
}
printf("要再玩一次嗎??要(1)不要(0)\n");
scanf("%d",&z);
if(z==0){
break;
}
else{
continue;
}
system("pause");
return 0;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.60.107.233
推
06/23 12:54, , 1F
06/23 12:54, 1F
→
06/23 12:55, , 2F
06/23 12:55, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章