第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

我的代碼可以運(yùn)行可是結(jié)果為什么不對(duì)

#include<iostream>
#include<stdlib.h>
using namespace std;
???
int getMaxorMin(int *arr,int count,bool ismax)
{
int temp;
if(ismax)
{
temp=arr[0];
for(int i=1;i<count;i++)
{
if(temp<arr[i])
{
temp=arr[i];
}
}
return temp;
}
if(ismax)
{
temp=arr[0];
for(int i=1;i<count;i++)
{
if(temp>arr[i])
{
temp=arr[i];
}
}
return temp;
}
}
int main(void)
{
int ismax;
cin>>ismax;
int arr1[4]={1,5,7,2};
cout<<getMaxorMin(arr1,4,ismax)<<endl;
system("pause");
return 0;
}

正在回答

3 回答

為什么你有8個(gè){卻只有7個(gè) };注意下return的位置和一開始定義的在一個(gè)大括號(hào)里面

0 回復(fù) 有任何疑惑可以回復(fù)我~

①你在getMaxorMin里用了兩個(gè)if(isMax)。if(isMax)的意思是如果isMax結(jié)果為true則怎么怎么樣?,F(xiàn)在如果傳入isMax=true就會(huì)有兩個(gè)入口,如果isMax=false就會(huì)沒有入口。
建議:
if(isMax)
{
...
}
else
{
...
}
②你在getMaxorMin里需要的是布爾型的isMax,在main函數(shù)里傳入的是整型的isMax,不匹配。(不知道這個(gè)會(huì)不會(huì)有問(wèn)題,還沒有試過(guò))
③你在main函數(shù)中聲明的isMax沒有賦初值,可能導(dǎo)致編譯時(shí)隨機(jī)賦值。
在下才疏學(xué)淺,說(shuō)的有什么不對(duì)的還請(qǐng)見諒。

0 回復(fù) 有任何疑惑可以回復(fù)我~

#include<iostream>
#include<stdlib.h>
using namespace std;
???
int getMaxorMin(int *arr,int count,bool ismax)
{
int temp;
if(ismax)
{
temp=arr[0];
for(int i=1;i<count;i++)
{
if(temp<arr[i])
{
temp=arr[i];
}

else
{
?if(temp>arr[i])
?{
??temp=arr[i];
?}
}


if(temp>arr[i])
{
temp=arr[i];
}
}
return temp;
}
}
int main(void)
{
int arr1[4]={1,5,7,2};
bool ismax =false;
cin>>ismax;
?

cout<<getMaxorMin(arr1,4,ismax)<<endl;
system("pause");
return 0;
}

改完后的代碼,請(qǐng)參考

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

學(xué)霸985

你的這個(gè)輸入什么就輸出什么,,
2019-08-03 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
C++遠(yuǎn)征之起航篇
  • 參與學(xué)習(xí)       290964    人
  • 解答問(wèn)題       817    個(gè)

C++亮點(diǎn)盡在其中,本課程是在C語(yǔ)言基礎(chǔ)上的一個(gè)延伸,得以升華

進(jìn)入課程

我的代碼可以運(yùn)行可是結(jié)果為什么不對(duì)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)