#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
constint SIZE = 5;
int array[SIZE];
int choice;
void arrEnter()
{
for(int i=0;i<5;++i)
{
cin >> array[i];
}
}
void arrSum()
{
int sum=0;
for (int i=0; i<5; ++i)
{
sum+=array[i];
}
cout << "The sum of the array is " << sum;
}
void meanArr()
{
int mean=0;
for (int i =0; i<5; ++i)
{
mean+=array[i];
}
mean /=5; //we know it will only be out of 5 numbers
cout << "The mean of this array is " << mean;
}
void displayArr()
{
for (int i=0; i<5; ++i)
{
cout << array[i] << ",";
}
}
int main()
{
cout << "Please input values for an array of five integers: ";
arrEnter();
cout << "Choose what to do with this array: ";
cout << "1. Sum " << endl;
cout << "2. Mean " <<endl;
cout << "3. Display Array " << endl;
cout << "4. Edit Array " << endl;
cout << "5.Exit " << endl;
cin >> choice;
switch(choice)
{
case 1:
arrSum();
break;
case 2:
meanArr();
break;
case 3:
displayArr();
break;
case 4:
arrEnter();
break;
case 5:
cout << "Thanks for using this program" ;
}
system ("read");
return 0;
}
The problem is a name collision with something in the standard namespace, thanks to your use of usingnamespace std;, and the way that the LLVM folks wrote the standard library. Note: they didn't break any rules.
Remove your using-statement and call things by their full name, or qualify array as ::array. This breaks (under at least some versions of the LLVM/Clang compiler) because some part of the standard library that you've included includes a declaration of the name std::array. Since you've imported everything in namespace std into the global namespace, there's a name collision; the compiler cannot determine which "array" you mean.
There has been plenty of stuff written as to why usingnamespace x is a bad idea, and this is why. You're lucky because your code doesn't compile, but if you weren't, the behavior of your code could silently change. Bugs like that are horrible to diagnose.
P.S.: you might have got better or quicker help if you posted the entire text of the error message, verbatim.
#include <iostream>
usingnamespace std;
constint SIZE = 5;
void arrEnter(int anArray[])
{
for(int i=0;i<5;++i)
{
cin >> anArray[i];
}
}
void arrSum(int anArray[])
{
int sum=0;
for (int i=0; i<5; ++i)
{
sum+=anArray[i];
}
cout << "The sum of the array is " << sum;
}
void meanArr(int anArray[])
{
int mean=0;
for (int i =0; i<5; ++i)
{
mean+=anArray[i];
}
mean /=5; //we know it will only be out of 5 numbers
cout << "The mean of this array is " << mean;
}
void displayArr(int anArray[])
{
for (int i=0; i<5; ++i)
{
cout << anArray[i] << ",";
}
}
int main()
{
int array[SIZE];
int choice;
cout << "Please input values for an array of five integers: ";
arrEnter(array);
cout << "Choose what to do with this array: ";
cout << "1. Sum " << endl;
cout << "2. Mean " <<endl;
cout << "3. Display Array " << endl;
cout << "4. Edit Array " << endl;
cout << "5. Exit " << endl;
cin >> choice;
switch(choice)
{
case 1:
arrSum(array);
break;
case 2:
meanArr(array);
break;
case 3:
displayArr(array);
break;
case 4:
arrEnter(array);
break;
case 5:
cout << "Thanks for using this program\n";
break;
default:
cout << "Bad choice\n";
}
return 0;
}