この課題のために、私の教授は、ユーザーに 3 つの整数を入力し、大きいものから小さいものへ順に出力するよう求めるプログラムを作成するように私に命じました。例: 入力は 10, 4, 6 出力は 10, 6, 4 である必要があります if else ステートメントの使用のみが許可されており、これはこれまでのところ私が持っているものですが、コンパイルすると、変数 position_1 - position_3 は初期化されておらず、出力にも問題があります。
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
int z;
int position_1;
int position_2;
int position_3;
cout<<"Please enter your first integer value"<<endl;
cin>>x;
cout<<"Please enter your second integer value"<<endl;
cin>>y;
cout<<"Finally enter your third integer value"<<endl;
cin>>z;
if(x>y && x>z)
x=position_1;
else if (x >y && x < z)
x=position_2;
else if (x <y && x > z)
x=position_2;
else
x=position_3;
if(y>x && y>z)
y=position_1;
else if (y >x && y < z)
y=position_2;
else if (y <x && y > z)
y=position_2;
else
y=position_3;
if(z>x && z>y)
z=position_1;
else if (z >x && z < y)
z=position_2;
else if (z <x && z > y)
z=position_2;
else
z=position_3;
cout<<position_1 + " " + position_2 + " " + position_3.\n;
system("pause");
return 0;
}