waheedrafiq
February 23rd, 2003, 04:48 AM
Guy's i am having problems with this code for some reason its from a book called C++ for Dummies 4th Edition a chapter Arrays
here is the code O i am using MS-Visual C++ // Array Demo - demonstrate the use of arrays
// by reading a swquence of integers and then
// displaying them in order
#include <iostream.h>
int sumArrary( int intergerArray[], int sizeOfloatArray);
void displayArray(int integerArrary[], int sizeOfloatArray);
int main(int nArg, char* pszArgs[])
{
int nAccumulator =0;
cout << "This program sums values entered"
<< "by the user \n";
cout <<"Terminate the loop by entering "
<< "a negative number \n";
// store numbers into an array
int inputValues[128];
int numberOfValues =0;
for (; numberOfValues < 128; numberOfValues++)
{
// fetch another number
int integerValue;
cout << "Enter next number: ";
cin >> integerValue;
//if its negative.....
if(integerValue < 0 )
{
// then exit
break;
{
inputValues[numberOfValues] = integerValue;
}
displayArray( inputValues , numberOfValues);
cout<<"The sum is "
<< sumArrary(inputValues, numberOfValues)
<< "\n";
return 0;
}
void displayArray(int integerArray[], int sizeOfArray)
{
cout <<"The value of the array is :\n";
for ( int i =0; i < sizeOfArray[i]; i++)
{
cout.width(3);
cout << i <<": " << integerArray[i] << "\n";
}
cout <<"\n";
}
int sumArray(int integerArray[], int sizeOfArray)
{
int accumulator = 0;
for ( int i = 0; i < sizeOfArray; i++)
{
accumulator += integerArray[i];
}
return accumulator;
}
and here are the errors that i am getting
:\My Documents\cprograms\arraydemo.cpp(54) : error C2601: 'displayArray' : local function definitions are illegal
C:\My Documents\cprograms\arraydemo.cpp(66) : error C2601: 'sumArray' : local function definitions are illegal
C:\My Documents\cprograms\arraydemo.cpp(76) : fatal error
C1004: unexpected end of file found
Error executing cl.exe.
arraydemo.obj - 3 error(s), 0 warning(s)
the file is attach to this post if any one of you can help me out here i would be gratefull and will own you a pint :)
here is the code O i am using MS-Visual C++ // Array Demo - demonstrate the use of arrays
// by reading a swquence of integers and then
// displaying them in order
#include <iostream.h>
int sumArrary( int intergerArray[], int sizeOfloatArray);
void displayArray(int integerArrary[], int sizeOfloatArray);
int main(int nArg, char* pszArgs[])
{
int nAccumulator =0;
cout << "This program sums values entered"
<< "by the user \n";
cout <<"Terminate the loop by entering "
<< "a negative number \n";
// store numbers into an array
int inputValues[128];
int numberOfValues =0;
for (; numberOfValues < 128; numberOfValues++)
{
// fetch another number
int integerValue;
cout << "Enter next number: ";
cin >> integerValue;
//if its negative.....
if(integerValue < 0 )
{
// then exit
break;
{
inputValues[numberOfValues] = integerValue;
}
displayArray( inputValues , numberOfValues);
cout<<"The sum is "
<< sumArrary(inputValues, numberOfValues)
<< "\n";
return 0;
}
void displayArray(int integerArray[], int sizeOfArray)
{
cout <<"The value of the array is :\n";
for ( int i =0; i < sizeOfArray[i]; i++)
{
cout.width(3);
cout << i <<": " << integerArray[i] << "\n";
}
cout <<"\n";
}
int sumArray(int integerArray[], int sizeOfArray)
{
int accumulator = 0;
for ( int i = 0; i < sizeOfArray; i++)
{
accumulator += integerArray[i];
}
return accumulator;
}
and here are the errors that i am getting
:\My Documents\cprograms\arraydemo.cpp(54) : error C2601: 'displayArray' : local function definitions are illegal
C:\My Documents\cprograms\arraydemo.cpp(66) : error C2601: 'sumArray' : local function definitions are illegal
C:\My Documents\cprograms\arraydemo.cpp(76) : fatal error
C1004: unexpected end of file found
Error executing cl.exe.
arraydemo.obj - 3 error(s), 0 warning(s)
the file is attach to this post if any one of you can help me out here i would be gratefull and will own you a pint :)