佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 847|回复: 2

c++ coding problem

[复制链接]
发表于 28-10-2007 11:14 AM | 显示全部楼层 |阅读模式
请大家帮帮忙。。。
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.

要怎样开始呢?请大家帮帮忙。。。
回复

使用道具 举报


ADVERTISEMENT

发表于 28-10-2007 09:39 PM | 显示全部楼层
  1. #include <iostream>
  2. #include <ctime>
  3. #include <conio.h>
  4. using namespace std;

  5. int MAX_QUESTION=20;
  6. int getQuestion();
  7. bool checkCorrect(int,int);

  8. int main(){
  9.     int correct(0);
  10.     double mark(0);
  11.    
  12.     cout << "------------------" << endl;
  13.     cout << "Addition Question" << endl;
  14.     cout << "------------------" << endl << endl;
  15.    
  16.     for(int i=0;i<MAX_QUESTION;i++){
  17.             cout << i+1 << " : ";
  18.             correct += getQuestion();
  19.     }
  20.     cout << endl;
  21.    
  22.     mark = correct * 100 / MAX_QUESTION;
  23.    
  24.     cout << "------------------" << endl;
  25.     cout << "Correct : " << correct << endl;
  26.     cout << "Mark    : " << mark << "%" << endl;
  27.     cout << "------------------" << endl;
  28.     getch();
  29.    
  30.     return 0;
  31. }

  32. int getQuestion(){
  33.      srand(time(NULL));
  34.      int number1 = rand()%9 + 1;
  35.      int number2 = rand()%9 + 1;
  36.      int enter(0);
  37.      
  38.      cout << "\t" << number1 << " + " << number2 << " = ";
  39.      cin >> enter;
  40.      
  41.      if(checkCorrect(enter, number1+number2)){
  42.          cout << "   Correct." << endl;
  43.          return 1;
  44.      } else{
  45.          cout << "  Wrong." << endl;
  46.          return 0;
  47.      }
  48. }

  49. bool checkCorrect(int a, int b){
  50.      return a == b ? true : false;
  51. }
复制代码
回复

使用道具 举报

 楼主| 发表于 29-10-2007 05:42 PM | 显示全部楼层

回复 #2 呵呵哟 的帖子

啊!!! 整题答案哦!!!谢谢你!! 爱死你了!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 18-9-2025 07:54 PM , Processed in 0.103506 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表