Hey guys. Here' some baby stuff for you. Any advice as to how this might work will be great.
We're asked to create 2 arrays, size=20, one holds integers and the other doubles. The user enters the values via keyboard. Next, I have to figure out the average for both arrays. I have the headers set for both arrays already, but I'm stuck with the function calls, which need to be in the main. I declared them as
avgA=avg(arr1);
avgB=avg(arr2);
but obviously there's something wrong. I get the 2 errors that say arr1, arr2 are undeclared identifiers. maybe i've just been looking into it so deeply, or maybe it's coz I can't think anymore. =(
Here's the rest of the code:
#include
using namespace std;
int readData(int[]);
int readData(double[]);
double avg(int[]);
double avg(double[]);
const int SIZE=20;
int main()
{
int a[SIZE];
double b[SIZE], avgA, avgB;
readData(a);
readData(b);
avgA=avg(arr1);
avgB=avg(arr2);
return 0;
}
/********/
int readData(int arr1[SIZE])
{
cout<<"\nEnter a number (integers) "<< SIZE <<" times."<
We're asked to create 2 arrays, size=20, one holds integers and the other doubles. The user enters the values via keyboard. Next, I have to figure out the average for both arrays. I have the headers set for both arrays already, but I'm stuck with the function calls, which need to be in the main. I declared them as
avgA=avg(arr1);
avgB=avg(arr2);
but obviously there's something wrong. I get the 2 errors that say arr1, arr2 are undeclared identifiers. maybe i've just been looking into it so deeply, or maybe it's coz I can't think anymore. =(
Here's the rest of the code:
#include
using namespace std;
int readData(int[]);
int readData(double[]);
double avg(int[]);
double avg(double[]);
const int SIZE=20;
int main()
{
int a[SIZE];
double b[SIZE], avgA, avgB;
readData(a);
readData(b);
avgA=avg(arr1);
avgB=avg(arr2);
return 0;
}
/********/
int readData(int arr1[SIZE])
{
cout<<"\nEnter a number (integers) "<< SIZE <<" times."<
[Error: Irreparable invalid markup ('<endl;>') in entry. Owner must fix manually. Raw contents below.]
Hey guys. Here' some baby stuff for you. Any advice as to how this might work will be great.
We're asked to create 2 arrays, size=20, one holds integers and the other doubles. The user enters the values via keyboard. Next, I have to figure out the average for both arrays. I have the headers set for both arrays already, but I'm stuck with the function calls, which need to be in the main. I declared them as
avgA=avg(arr1);
avgB=avg(arr2);
but obviously there's something wrong. I get the 2 errors that say arr1, arr2 are undeclared identifiers. maybe i've just been looking into it so deeply, or maybe it's coz I can't think anymore. =(
Here's the rest of the code:
<lj-cut>
#include <iostream>
using namespace std;
int readData(int[]);
int readData(double[]);
double avg(int[]);
double avg(double[]);
const int SIZE=20;
int main()
{
int a[SIZE];
double b[SIZE], avgA, avgB;
readData(a);
readData(b);
avgA=avg(arr1);
avgB=avg(arr2);
return 0;
}
/********/
int readData(int arr1[SIZE])
{
cout<<"\nEnter a number (integers) "<< SIZE <<" times."<<endl;
for (int i=0; i < SIZE; i++)
{
cin>>arr1[i];
}
return 0;
}
/********/
int readData(double arr2[SIZE])
{
cout<<"\nEnter a number (doubles) " << SIZE <<" times."<<endl;
for (int j=0; j < SIZE; j++)
{
cin>>arr2[j];
}
cout<<endl;
return 0;
}
/********/
double avg(int arr1)
{
return (double)arr1/SIZE;
}
/********/
double avg(double arr2)
{
return (double)arr2/SIZE;
}
</lj-cut>
Thanks so much for any help.
We're asked to create 2 arrays, size=20, one holds integers and the other doubles. The user enters the values via keyboard. Next, I have to figure out the average for both arrays. I have the headers set for both arrays already, but I'm stuck with the function calls, which need to be in the main. I declared them as
avgA=avg(arr1);
avgB=avg(arr2);
but obviously there's something wrong. I get the 2 errors that say arr1, arr2 are undeclared identifiers. maybe i've just been looking into it so deeply, or maybe it's coz I can't think anymore. =(
Here's the rest of the code:
<lj-cut>
#include <iostream>
using namespace std;
int readData(int[]);
int readData(double[]);
double avg(int[]);
double avg(double[]);
const int SIZE=20;
int main()
{
int a[SIZE];
double b[SIZE], avgA, avgB;
readData(a);
readData(b);
avgA=avg(arr1);
avgB=avg(arr2);
return 0;
}
/********/
int readData(int arr1[SIZE])
{
cout<<"\nEnter a number (integers) "<< SIZE <<" times."<<endl;
for (int i=0; i < SIZE; i++)
{
cin>>arr1[i];
}
return 0;
}
/********/
int readData(double arr2[SIZE])
{
cout<<"\nEnter a number (doubles) " << SIZE <<" times."<<endl;
for (int j=0; j < SIZE; j++)
{
cin>>arr2[j];
}
cout<<endl;
return 0;
}
/********/
double avg(int arr1)
{
return (double)arr1/SIZE;
}
/********/
double avg(double arr2)
{
return (double)arr2/SIZE;
}
</lj-cut>
Thanks so much for any help.
