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

时间:2022-03-17 19:55:21

I'm supposed to use a test harness for homework to check if a module works. I've only done 2 tests so far, but when I debug the program, it asks me for an input rather than using what I've provided in the code. What did I do wrong?

我应该使用测试工具来做家庭作业来检查模块是否有效。到目前为止我只做了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 个解决方案

#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;

    ...
}

It asks for input because you ask for input in your function. It doesn't matter what you pass to it because you are changing it with the inputs you ask for in the function itself.

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

#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;

    ...
}

It asks for input because you ask for input in your function. It doesn't matter what you pass to it because you are changing it with the inputs you ask for in the function itself.

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