How to Program の練習問題 2.19 のプログラムを書こうとしていたのですが、うまくいきませんでした。
このプログラムは、ユーザーに 3 つの整数を入力させ、それらの整数のsum
、average
、およびを表示させることになっています。product
私が抱えている唯一の問題は、最大と最小を表示することです。プログラムを実行して 3 つの整数を入力する(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 私はこれを勉強するためにやっています。これは宿題ではありません。