### Arrays in a function

I need help with this program. I need to use 3 different functions. The first function should read in N amount of integer values from the user.If any values are less than 1, store a value of 0 instead of the input value.
Second should go through the entire array to find the largest value and
send the largest value back to the main program.
The last is just an output function where I write out all of the array values and the largest value.

Here is the program. It is very rough but I just want feed back and I really want to learn how to do this properly so please give me feedback so I can learn this.

#include <iostream>
using namespace std;
#define ARRSIZE 20
void getData(int A[]);
void findBig(int A[ARRSIZE], int max)
int main()
{
int A;
int big;
getData(A,20);
findBig(A[ARRSIZE]);
}
void getData(int A[])
{
int A[ARRSIZE],num;
cout<<"Please enter 20 numbers greater than or equal to 1."<<endl;
for (int i=0; i<ARRSIZE;i++)
{
cin>>num;
A[i]=num;
while(num<1)
{
num==0;
A[i]=num;
}
}
}
void findBig(int A[], int max)
{
int i;
int max=A[i];
for(int i=0;i<ARRSIZE;i++)
{
if(A[i]>max)
max=A[i];
}
}
Last edited on
Nice code.

EDIT:

Sorry for my wiseass post. I could've swore your original post just had a block of code with no question.
Last edited on
In your function "getData", your while loop is not prompting for them to re-enter a number greater than 1. You may want to consider prompting the user to re-enter the number for that index of the array, within that while loop.

Other than that, this program looks good!

EDIT::
Upon re-reading your program objective, I realize that you are not asked to prompt for another input.

This code looks good!
Last edited on
Topic archived. No new replies allowed.