2012-12-25 154 views
1

我在C.堆棧中循環一遍又一遍

假設老師已經聘請你當一名軟件顧問,寫一個程序,這將有助於講師加快他們的選擇題標記有程序。對於這個程序,你需要做一個原型程序來使用C編程語言來標記包含10個選擇題的問題論文。

每個問題有四個選擇a,b,c和d。講師需要查看學生的答題卡並逐個輸入答案(a,b,c和d) 。 C程序必須將答案與解決方案進行比較,如果答案正確,則輸出/,如果答案不正確,則輸出x,然後程序必須計算從總共10個標記中獲得的標記。

示例。

question 1: a/ 
question 1: bx 

假設答案是(A,B,C,d,A,B,C,d,A,B)分別與我要問用戶再次和ny到環退出循環。

z='y','n'; 
while (z=='y') 
{ 
    while (count<10) 
    { 
     printf("\n question #%d:",count+1); 
     r=getch(); 

     while(r!='a' && r!='b' && r!='c' && r!='d') 
     { 
      r=getch(); 
     } 
     putch(r);  

     if (r==answer[count]) 
     { 
      putch('/'); 
      mark=mark+1; 
     } 
     else 
     { 
      putch('x'); 
     } 
     count++; 
    } 
} 

printf("\n\n the mark is: %d/10", mark); 

printf("\n\n continue? (y/n)"); 
z=getch();  
printf("\n\n "); 
system("pause"); 
return(0); 
+0

中的z = 'Y', 'N';'構建體是小怪異。海灣合作委員會通常會給予警告。它將''y''分配給'z',然後忽略該值;它評估''n''並忽略這一點。放下''''''''一點。 –

回答

0

你必須用另一個循環的一切,應該打破,當用戶輸入'n'

是這樣的:

bool finished = false; 
while (!finished) { 
    // reset status of variables 
    while (count < 10) { 
    // your actual code 
    } 

    finished = /* users typed y or n */ 
} 
相關問題