我试图为 How to Program 中的练习 2.19 编写一个程序,但遇到了一些困难。
该程序应该让用户输入三个整数,然后显示这些整数的sum
、average
和product
。
我遇到的唯一问题是显示最大和最小。当我运行程序并输入三个整数(8, 9, and 10)
时,输出为Smallest is 8
AND
Smallest is 9
.
我希望你能告诉我为什么。
#include <iostream>
using namespace std;
int main ()
{ int x, y, z, sum, ave, prod;
cout << "Input three different integers ";
cin >> x >> y >> z;
sum = x + y + z;
cout << "\nThe sum is " << sum;
ave = (x + y + z) / 3;
cout << "\nThe average is " << ave;
prod = x * y * z;
cout << "\nThe product is " << prod;
if (x < y, x < z)
{cout << "\nSmallest is " << x;}
if (y < x, y < z)
{cout << "\nSmallest is " << y;}
if (z < x, z < y)
{cout << "\nSmallest is " << z;}
if (x > y, x > z)
{cout << "\nLargest is " << x << endl;}
if (y > x, y > z)
{cout << "\nLargest is " << y << endl;}
if (z > x, z > y)
{cout << "\nLargest is " << z << endl;}
return 0;
}
PS我这样做是为了学习,这不是家庭作业。