私は学校のラボの割り当てに関する質問があり、私は誰かが私に少しこれを明確にすることができたと思っていました。私は答えを探しているわけではなく、ただのアプローチです。私は本の説明を完全に理解することができませんでした。配列機能。
質問:プログラムで、三つの引数受け付ける機能書く:アレイ、アレイのサイズ、および数nを。 配列に整数が含まれているとします。この関数は、数値nより大きい配列内のすべての数値を と表示する必要があります。
これは私が今持っているものである:C++側面から別に
/*
Programmer: Reilly Parker
Program Name: Lab14_LargerThanN.cpp
Date: 10/28/2016
Description: Displays values of a static array that are greater than a user inputted value.
Version: 1.0
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void arrayFunction(int[], int, int); // Prototype for arrayFunction. int[] = array, int = size, int = n
int main()
{
int n; // Initialize user inputted value "n"
cout << "Enter Value:" << endl;
cin >> n;
const int size = 20; // Constant array size of 20 integers.
int arrayNumbers[size] = {5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; // 20 assigned values for the array
arrayFunction(arrayNumbers, size, n); // Call function
return 0;
}
/* Description of code below:
The For statement scans each variable, if the array values are greater than the
variable "n" inputted by the user the output is only those values greater than "n."
*/
void arrayFunction(int arrayN[], int arrayS, int number) // Function Definiton
{
for (int i=0; i<arrayS; i++)
{
if (arrayN[i] > number)
{
cout << arrayN[i] << " ";
cout << endl;
}
}
}
あまりにも多くのことをあきらめることなしに手助けするのは少し難しいです:)。あなたの課題の全体的な話題の上の斜体の質問ですか? – Lehu
*この関数は、配列中の数字のうち「n」より大きい数字をすべて表示する必要があります。*これは、関数内で 'cin'からの読み込みが必須ではないことを意味します。 –
ループカウントを20にしないでください。ループカウントを 'size'にしてください。渡された配列のスロット数が20未満の場合は、配列を超えて書き込みが行われ、*未定義の動作*が発生します。 –