Re: [問題] 個性測驗程式
看板C_and_CPP作者cismjmgoshr (--???--)時間10年前發表 (2014/12/12 13:31), 10年前編輯推噓0(0推 0噓 2→)留言2則, 1人參與討論串3/3 (看更多)
※ 引述《OhyaPTT (Ohya)》之銘言:
: 已爬文
: 這次老師是出
: 個性測驗程式開發
: 就是
: 回答問題一後
: 是就跳問題幾
: 否就跳問題幾這樣
: 雖然有提示了
: 雖然有爬文了
: 但是還是不懂怎麼寫...
: 然後只能用陣列和迴圈
: 跪求講解QQ
: -----
: Sent from JPTT on my HTC Desire 600.
用有限狀態機試試
第1個問題 答Y跳到第2題,答N跳到第3題
第2個問題 答Y跳到第4題,答N跳到第5題
第3個問題 答Y跳到第6題,答N跳到第7題
...
int QuestionList[][2] = {
{2,3},
{4,5},
{6,7},
...
}
char *QuestionText[] = {
"Question1: ...",
"Question2: ...",
"Question3: ...",
...
}
int QuestionNum=1;
char Answer;
while (...)
{
printf("%s",QuestionText[ QuestionNum ] );
scanf("%s",&Answer);
if ( Answer == 'Y' )
QuestionNum = QuestionList[ QuestionNum ][ 0 ];
else
QuestionNum = QuestionList[ QuestionNum ][ 1 ];
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.132.191.97
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1418391074.A.2AA.html
※ 編輯: cismjmgoshr (220.132.191.97), 12/12/2014 21:34:19
→
01/05 11:38, , 1F
01/05 11:38, 1F
→
01/05 11:38, , 2F
01/05 11:38, 2F
討論串 (同標題文章)