Xcode "No matching function for call to 'max'" 上的错误

Error on Xcode "No matching function for call to 'max'"

本文关键字:max 错误 to matching No function for call Xcode      更新时间:2023-10-16

这是我正在使用的语句,但它说没有匹配函数来调用"max"

max((used_minutes-Included_Minutes)*extra_charge,0) 

任何帮助将不胜感激。

编辑

法典

 int used_minutes; const int Included_Minutes = 300;
 double total_charge, extra_charge;
 cout << "Enter the number of phone call minutes: ";
 cin >> used_minutes;
 cout <<"Number of phone call minutes used - included in the base plan: " << min(used_minutes,Included_Minutes) << endl;
 cout <<"Number of phone call minutes used - not included in the base plan: "<< max(used_minutes-Included_Minutes,0) << endl;
 extra_charge = 0.10;
 cout <<"Cost of excess phone call minutes: $"<<fixed << setprecision(2) << max(used_minutes-Included_Minutes)*extra_charge, 0) <<endl;

max()要求第一个和第二个参数属于同一类型。 extra_charge 是一个双精度值,导致第一个和第二个参数具有不同的类型。尝试:

max((used_minutes-Included_Minutes)*extra_charge,0.0)