这一方案“FindMIn”具有两种价值,其参数和价值最小。 我试图改变我的方案,以便它以三个价值作为参数,并且回报三个价值中最小的数值。 这正是我迄今为止如何呢?
#include <iostream>
using namespace std;
//function prototypes go before main - parameters much match those of the function definition
int FindMin(int x, int y);
//place prototype for PrintOutput here
int main()
{
int n1, n2, n3;
int result;
char answ = Y ;
while (answ == Y )
{
cout << "Please enter three numbers..." << endl;
cin >> n1 >> n2 >> n3;
result = FindMin(n1, n2); //function call
//place call to function PrintOutput here
cout << "Would you like to run the program again? Enter Y or N" << endl;
cin >> answ;
}
return(0);
}
//***************************************************************
//FindMin - returns the minimum of two values
//***************************************************************
int FindMin(int a, int b)
{
if (a < b)
return a;
else
return b;
}
//******************************************************************
//PrintOutput - prints the values input and the smallest of the
//three values
//******************************************************************
void PrintOutput(int first, int second, int min)
{
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "The minimum value of " << first << ", " <<
second << ", is " << min << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
}