#include<iostream>
using namespace std;
int Max1(int m,int n);
int Max1(int m,int n,int o);
double Max1(double m,double n);
double Max1(double m,double n,double o);
void main()
{
int a[2],b,c,d; char ch;
double h,i,k;
A: cout<<"請輸入要比較的數的個數:(兩個或三個)"<<endl;
cin>>a[0];
if(a[0]!=2&&a[0]!=3) {
cout<<"對不起,妳輸入錯誤,請重新選擇。"<<endl;
goto A;
}
B: cout<<"請輸入要比較的數的類型:(1-int,2-double)"<<endl;
cin>>a[1];
switch(a[0]){
case 2: {
if(a[1]==1) {
cout<<"請輸入要比較的兩個int型數:" <<endl;
cin>>b>>c;
cout<<"較大的數為:"<<Max1(b,c)<<endl;
break;
}
else if(a[1]==2) {
cout<<"請輸入要比較的兩個double型數:" <<endl;
cin>>h>>i;
cout<<"較大的數為:"<<Max1(h,i)<<endl;
break;
}
else {
cout<<"對不起,妳輸入錯誤,請重新選擇。"<<endl;
goto B;
}
}
case 3: {
if(a[1]==1) {
cout<<"請輸入要比較的三個int型數:"<<endl;
cin>>b>>c>>d;
cout<<"較大的數為:"<<Max1(b,c,d)<<endl;
break;
}
else if(a[1]==2) {
cout<<"請輸入要比較的三個double型數:"<<endl;
cin>>h>>i>>k;
cout<<"較大的數為:"<<Max1(h,i,k)<<endl;
break;
}
else{
cout<<"對不起,妳輸入錯誤,請重新選擇。"<<endl;
goto B;
}
}
}
cout<<"重新運行?Y or N?"<<endl<<"輸入Y重新運行,輸入其它字符退出。"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y') main();
else exit;
system("pause");
}
int Max1(int m,int n)
{
if(m>n) return m;
else return n;
}
int Max1(int m,int n,int o)
{
int x;
x=Max1(m,n);
x=Max1(x,o);
return (x);
}
double Max1(double m,double n)
{
if(m>n) return m;
else return n;
}
double Max1(double m,double n,double o)
{
double x;
x=Max1(m,n);
x=Max1(x,o);
return (x);
}