Closed. This question needs details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
3年前关闭。
我正在调用的功能是
课程数的输入是5
和学分是3,3,3.5,4,2.5
我得到了总学时,但似乎无法显示学费?
谢谢你
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
3年前关闭。
int main()
{
double tuitionCalc(int sumCreditHoursTaken);
int numCourses;
double total = 0.0;
double tuitionCost= 0.0;
cout << "\t\t This Program calculates a student's total number of\n";
cout << "\t\tcredit hours and tution for a given semester.\n";
cout << "\nPlease enter the number of Courses you will be taking this semester: ";
cin >> numCourses;
for ( int count = 1; count <= numCourses; count++)
{
double sumCreditHoursTaken;
cout << " please enter the number of credit hours for course" << count << ": ";
cin >> sumCreditHoursTaken;
total += sumCreditHoursTaken;
}
cout << fixed << showpoint << setprecision(2);
cout << "Your Total number of credit hours is: " << total << endl;
cout << "Your total tuition will be: $" << tuitionCalc(tuitionCost) << "\n\n";
return 0;
}
我正在调用的功能是
double tuitionCalc(int sumCreditHoursTaken)
{
double tuitionCost = 0.0;
double costCreditHour = 147.00;
double maxHoursFullTuition = 12;
double maintFeeAddOn = 29.33;`
if (sumCreditHoursTaken <= maxHoursFullTuition)
cout<< " " << (sumCreditHoursTaken * costCreditHour);
else if (sumCreditHoursTaken > maxHoursFullTuition)
cout << " " << (maxHoursFullTuition * costCreditHour) + ((sumCreditHoursTaken - maxHoursFullTuition) * maintFeeAddOn);
return tuitionCost;
}
课程数的输入是5
和学分是3,3,3.5,4,2.5
我得到了总学时,但似乎无法显示学费?
谢谢你
最佳答案
您实际上从未在tuitionCost
方法中为tuitionCalc()
分配值,因此它将始终为0.0
。
详细说明:您正在从tuitionCost
返回tuitionCalc()
。您首先初始化tuitionCost = 0.0
,但不要继续为其分配任何计算值。因此,当您返回tuitionCost
时,它将返回您将其初始化为的值:0.0
。
10-08 11:53