gpt4 book ai didi

c++ - Test Harness 要求输入而不是使用所写的内容(作业)

转载 作者:行者123 更新时间:2023-11-28 06:16:59 24 4
gpt4 key购买 nike

我应该在家庭作业中使用测试工具来检查模块是否正常工作。到目前为止我只做了 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;
}

}

最佳答案

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;

...
}

它要求输入,因为您要求在您的函数中输入。传递给它的内容并不重要,因为您正在使用您在函数本身中要求的输入来更改它。

关于c++ - Test Harness 要求输入而不是使用所写的内容(作业),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30062237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com