|
1鱼币
#include <iostream>
using namespace std;
void getScore(int &score);
void calcAverage(int, int, int, int, int);
int findLowest(int, int, int, int, int);
int main()
{
int a, b, c, d, e;
getScore(a);
getScore(b);
getScore(c);
getScore(d);
getScore(e);
calcAverage(a, b, c, d, e);
}
void getScore(int &score)
{
cout << "Enter a test score: ";
cin >> score;
while (score < 0 || score > 100)
{
cout << "Do not accept test scores"
<<"lower thana 0 or higher than 100\n";
cout << "Enter a test score: ";
cin >> score;
}
}
void calcAverage(int a, int b, int c, int d, int e)
{
double result5, result4, result;
result5 = (a+b+c+d+e);
result4 = findLowest(a, b, c, d, e);
result = (result5 - result4) / 4;
cout << "the average is " << result << endl;
}
int findLowest(int q, int w, int e, int r, int t)
{
if (q < w && q < e && q < r && q < t) // if else if 有没有更加简便的写法
return q;
else if (w < q && w < e && w < r && w < t)
return w;
else if (e < q && e < w && e < r && e < t)
return e;
else if (r < q && r < w && r < e && r < t)
return r;
else if (t < q && t < w && t < e && t < r)
return t;
}
本帖最后由 Croper 于 2019-4-14 03:40 编辑
- int findLowest(int q, int w, int e, int r, int t)
- {
- __int64 *p=&q; //栈是8字节对齐;
- int i;
- for (i=1;i<5;++i)
- if (q>(int)p[i]) q=(int)p[i];
- return q;
- }
复制代码
|
|