测试线束要求输入而不是使用所写的内容(作业)

时间:2015-05-05 20:03:21

标签: c++

我应该使用测试工具来检查作业是否有效。到目前为止我只做了2次测试,但是当我调试程序时,它会要求我输入而不是使用我在代码中提供的内容。我做错了什么?

void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility);

using namespace std;

int main()

{
     bool full_time,
          eligibility;

     int  age,
          service_years,
          contribution;


     full_time = 0;
     eligibility = 0;
     service_years = 0;
     age = 0;



     retirement_eligibility(1, 30, 1, eligibility);
     if (eligibility == true){
          cout << "Test 1 passed" << endl;
     }
     else {
          cout << "Test #1 FAILED!" << endl;
          cout << " - Expected eligibility 1, got" << eligibility << endl;

     }
     retirement_eligibility(1, 29, 1, eligibility);
     if (eligibility == 2){
          cout << "Test 2 passed" << endl;
     }
     else {
          cout << "Test #2 FAILED!" << endl;
          cout << " - Expected eligibility 2, got" << eligibility << endl;

     }
}

void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility)
{

     cout << "Enter age: ";
     cin >> age;
     cout << "Enter years served: ";
     cin >> service_years;
     cout << "Are you a full time eployee?(1 for yes, 2 for no): ";
     cin >> full_time;

     if (full_time == true){
          if (age >= 30 && service_years >= 1){
               eligibility = true;
          }

          else{
               eligibility = false;
          }
     }

     else{
          eligibility = false;
     }

}

1 个答案:

答案 0 :(得分:1)

void retirement_eligibility(bool full_time, int age, int service_years, bool &eligibility)
{
    cout << "Enter age: ";
    cin >> age;
    cout << "Enter years served: ";
    cin >> service_years;
    cout << "Are you a full time eployee?(1 for yes, 2 for no): ";
    cin >> full_time;

    ...
}

它要求输入,因为您要求输入函数。你传递给它的并不重要,因为你正在用函数本身要求的输入来改变它。