在函数中找到minExam [英] Find minExam in the function

查看:85
本文介绍了在函数中找到minExam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚此功能出了什么问题.我需要在该功能中找到最低限度的考试.

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

推荐答案

根据您的描述,您的代码没有行为问题……只是API怪癖,但您对此问题的解释可能不正确.

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

无论哪种方式,如果您具有C ++ 11支持,则可以简单地编写此代码,而不必编写自己的手工函数,如注释中指出的那样:

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});

这篇关于在函数中找到minExam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆