int の配列とそのサイズが渡されるプログラムを作成する必要があります。これにより、平均を超える数値が出力されます。誰かが私のためにこの質問を解決するのを助けることができますか? 私はここに座って一体何を求めているのだろうと思っています。私はまだプログラミングに慣れていないので、何をすべきかわかりません。申し訳ありませんが、私は混乱しているだけです。助けてくれる人に感謝します。これは私がこれまで持っているすべてです:
これが更新されたコードですが、複数の平均値が表示されない理由や、正しい出力値を取得する方法がまだわかりません。
編集: average() 関数のいくつかの int 値を float に変更しましたが、最後の合計値にはまだ問題があります
#include <iostream>
using namespace std;
int average(int values[],int size);
int main(){
int size;
int values[] = {1,2,3,4,5,6};
cout << "Please input the size of the array" << endl;
cin >> size;
int output = average(values, size);
if(values[size]>output){
cout << "The values above average are: " << output << endl;
}
return 0;
}
int average(int values[],int size){
float temp=0.0;
for(int i=0;i<size;i++){
temp += values[i];
}
float end=temp/size;
return end;
}