為什么我的程序有錯誤?
#include<iostream>
#include<stdlib.h>
using namespace std;
?
int getMaxOrMin(int *arry, int count)
{
??? int temp=arry[0];
??? string a="最大值";
??? string b="最小值";
??? string c;
??? cout<<"請輸入最大值或最小值:"<<endl;
??? cin>>c;
???????
??? for(int i=1;i<count;i++)
??? {
??????? if (a==c)
??????? {
??? ?
??????????? if(temp<arry[i])
??????????? {
??????????????? temp=arry[i];
??????????? }
??????? }
?
??????? if(b==c)
?
??????? {
??????????? if(temp>arry[i])
??????? ??? {
??????????? temp=arry[i];
??????? ??? }
??????? }
??? }
??? return temp;
}
?
int main()
??? {
??????? int myArry[4]={3,9,7,4};
??????? cout<<getMaxOrMin(myArry,4);
??????? system("pause");
??????? return 0;
}? ?
2017-04-06
?if (a==c)你這里應該比較的是兩個字符串的地址是否相同,很明顯是不可能相同的。
2017-03-09
string?a="最大值";//字符串怎么可能等于一個數??? ????string?b="最小值";//同樣的 ????string?c; ????cout<<"請輸入最大值或最小值:"<<endl; ????cin>>c; ??????? ????for(int?i=1;i<count;i++) ????{ ????????if?(a==c)//這是要干哈???? ????????{ ????? ????????????if(temp<arry[i]) ????????????{ ????????????????temp=arry[i]; ????????????} ????????} ? ????????if(b==c)//同理自己改改吧!2017-03-09
cin空格