我開始編程C,並提出了一個簡短的測驗程序。該程序要求用戶輸入他們想要回答的問題的數量。那麼問題的格式是相同的(#+#+# - #),但每次都會生成隨機數。我的問題是如何向用戶顯示他們在程序結束時得到的正確答案的數量?我知道你將要執行打印˚F語句來顯示它,但我不知道還有什麼如何顯示正確答案的數量?
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>
main()
{
srand(time(NULL));
int NumQuestions = 0;
int responce = 0;
int loopcount = 0;
int answer = 0;
int NumCorrect = 0; // HOW TO GET THIS ???????????????????????????????
printf("\n\welcome to your math quize!\n ");
printf("\ntype the numer of questions you would like to answer: ");
scanf("%d", &NumQuestions); //number of questions.
while(loopcount<NumQuestions){
int n1 = 0;
int n2 = 0;
int n3 = 0;
int n4 = 0;
n1 = rand()% 9 + 1;
n2 = rand()% 9 + 1;
n3 = rand()% 9 + 1;
n4 = rand()% 9 + 1;
answer = n1 + n2 + n3 - n4;
printf("\n%d + %d + %d - %d =", n1, n2, n3, n4);
scanf("%d", &responce); // user answer
if(responce == answer)
printf("\ncorrect\n");
else
printf("\nincorrect\n");
loopcount++;
} //exit loop
printf("you got %d andswers correct!", NumCorrect); //????????????????????????????
getch();
} // end process
非常感謝我回答的問題和其他提示! – Arbin 2011-02-13 05:45:38