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
If it does, ditch it now - it's worse than useless. <iostream.h> does not exist in the ISO standard. It has been replaced by <iostream>, and a book that doesn't recognise that fact is wrong and is misleading you. What else has it got wrong if it can't get a simple thing like that right?
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there. -- Gordon Bell
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.