vendredi 31 janvier 2020

c++ checking each element of random array [closed]

I need to create a seperate function that I can run in my main that checks each element of the array I created with the size and random number limit. I need to have the parameters in the function (assignement) Basically I have to run the array, then run that function to check if it's within the limit then modify the array if it isn't. Any help/tips appreciated :)

2.Declare an array to hold 10 integer values3.Set the 10 values to a number between 1 and 50 using the rand function4.Create a function called “Limit” that takes as parameters the array name, the array length and a limiting value (between 1 and 50). It must check all the elements, and if any of the elements are larger than Limit, change them to that Limit value.5.Print out the list of 10 numbers, then call the function “Limit” and print out the numbers again.

This is what I have so far:

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
    srand(time(NULL));

    const int SIZE = 10;
    int Arr[SIZE];

    for (int i = 0; i < Arr; i++)
    {
        Arr[i] = rand() % 50;
        cout << Arr[i] << endl;

    }

    system("PAUSE");

}

int limit(int Arr, const int sizeOfArray)
{

    if (Arr)
    {

    }


}



Aucun commentaire:

Enregistrer un commentaire