大神幫幫我看看哪地方錯誤了
//知識點:bool類型,命名空間,輸入輸出
//題目要求:
//????????? 使用一個函數找出一個整形數組中的最大值或最小值。
#include<stdlib.h>
#include<iostream>
using namespace std;
namespace compA
int MaxorMin(int *arr,int N,bool maxmin)
{
?int temp=arr[0];
?if(maxmin)
?{??
??for(i=1;i<N;i++)
??{
????? if(temp<arr[i])
???{
????temp=arr[i];
???}
??}
?
?
?}
?
?else
??{
?????????????? for(i=1;i<N;i++)
??{
????? if(temp>arr[i])
???{
????temp=arr[i];
???}
??}
?}?
?return temp;
}
int main()
{
??? int arr[8]={1,2,3,4,5,6,7,8};
?bool maxmin=false;
?cin >> maxmin >> endl;
?cout << compA::MaxorMin(arr,8,maxmin) << endl;
}
2017-03-25
還有命名空間namespace compA后面加{}。函數必須放進{}。謝謝各位
2017-03-25
誒,我自己懂了。沒有? int? i,然后不能cin >> maxmin >> endl;必須cin>>maxmin;