查看: 847|回复: 2
|
c++ coding problem
[复制链接]
|
|
请大家帮帮忙。。。
case details : Generate 20 addition questions. Each question will have two operands with integer value from the range of 1 to 9. After displaying each question,prompt user to answer question. Computer will determine whether the user's answer is correct. Display necessary and appropriate comment. At the end of the test, computer must display the correct score for the test in percentage.
title: online test-addition question.
要怎样开始呢?请大家帮帮忙。。。 |
|
|
|
|
|
|
|
发表于 28-10-2007 09:39 PM
|
显示全部楼层
- #include <iostream>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- int MAX_QUESTION=20;
- int getQuestion();
- bool checkCorrect(int,int);
- int main(){
- int correct(0);
- double mark(0);
-
- cout << "------------------" << endl;
- cout << "Addition Question" << endl;
- cout << "------------------" << endl << endl;
-
- for(int i=0;i<MAX_QUESTION;i++){
- cout << i+1 << " : ";
- correct += getQuestion();
- }
- cout << endl;
-
- mark = correct * 100 / MAX_QUESTION;
-
- cout << "------------------" << endl;
- cout << "Correct : " << correct << endl;
- cout << "Mark : " << mark << "%" << endl;
- cout << "------------------" << endl;
- getch();
-
- return 0;
- }
- int getQuestion(){
- srand(time(NULL));
- int number1 = rand()%9 + 1;
- int number2 = rand()%9 + 1;
- int enter(0);
-
- cout << "\t" << number1 << " + " << number2 << " = ";
- cin >> enter;
-
- if(checkCorrect(enter, number1+number2)){
- cout << " Correct." << endl;
- return 1;
- } else{
- cout << " Wrong." << endl;
- return 0;
- }
- }
- bool checkCorrect(int a, int b){
- return a == b ? true : false;
- }
复制代码 |
|
|
|
|
|
|
|

楼主 |
发表于 29-10-2007 05:42 PM
|
显示全部楼层
回复 #2 呵呵哟 的帖子
啊!!! 整题答案哦!!!谢谢你!! 爱死你了!! |
|
|
|
|
|
|
| |
本周最热论坛帖子
|