Find minExam in the function

不羁的心 提交于 2019-12-11 11:22:43

问题


I cannot figure out what is wrong with this function. I need to find the nimimum exam in the function.

  void findMinExam( int exam1, int exam2, int exam3, int& minExam)
//***************************************************************************************
//Purpose: Determine the lowest exam score.
//Input: exam1, exam2, exam3, minExam
//Precondition: exam1, exam2, exam3, minExam have values and are valid.
//Output: int.
//Post condition: This function shows the lowest exam.
//Note: None. 
//****************************************************************************************
{
  if (exam1 < minExam)
     {
     minExam = exam1;
     }
  if (exam2 < minExam)
     {
     minExam = exam2;
     }
  if (exam3 < minExam)
     {
     minExam = exam3;
     }
}

回答1:


Based on your description, there is no behavior problem with your code... just API quirks, but your explanation of the issue may be incorrect.

Either way, if you have C++11 support, you could simply write this instead of your own hand-crafted function, as pointed out in the comments:

minExam = std::min({exam1, exam2, exam3, minExam});


来源:https://stackoverflow.com/questions/22925247/find-minexam-in-the-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!