I have recently been studying arrays and tried to write a console application that would intake, store, display, and display the sum of numbers input by the user but I keep getting an error! Why? What have I done? It appears to be correct but maybe I am just frustrated! Please help if you can.
Code:
//This prorgam inputs, stores, displays, and sums an array
//entered by the user.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
//declare protos
void displayArray(int indexOfArray, int arrayA[]);
int sumArray(int indexOfArray, int arrayB[]);
int main(int argc, char *argv[])
{
cout << "This program allows you to enter an array which is\n"
<< "then stored, summed, and ouput at the end of the program.\n"
<< "To terminate the program simply enter any negative number.\n"
<< endl;
//Declare the array for 100 numbers
int mainArray[100];
//start loop
for (int arrayCount = 0; arrayCount < 100; arrayCount++)
{
cout << endl
<< "Input your next number in the array: ";
//delcare input variable
int arrayInput;
cin >> arrayInput;
//check to make sure user wants to continue
if (arrayInput < 0)
{
break;
}
//else continue on and store the value in the array
mainArray[arrayCount] = arrayInput;
//jump back to the top of the loop and start over
}
//here the user has exited the loop with a negative and is going
//to now see the containments and sum of the array
cout << "\n\nYou have entered a negative number.\n\n"
<< "The sum of your array is: "
<< sumArray(arrayCount, mainArray)
<< "\n\nThe containments of your are are: \n\n";
displayArray(arrayCount, mainArray);
system("PAUSE");
return EXIT_SUCCESS;
}
//Sum Array - this function sums the numbers in the array
int sumArray(int indexOfArray, int arrayB[])
{
int accumulator = 0;
for (int i = 0; i < indexOfArray; i++)
{
accumulator += arrayB[i];
}
return accumulator;
}
//Display Array - this function shows the containments of an array
void displayArray(int indexOfArray, int arrayA[])
{
cout << "The value of the array is:" << endl;
for (int i = 0; i < indexOfArray; i++)
{
cout.width(3);
cout << i << ": " << arrayA[i] << endl;
}
cout << endl;
}
The bold code is where I get the error Dev-C++ says "In function 'int main(int, char**)':
name lookup of 'arrayCount' changed for new ISO 'for' scoping
using obsolete binding at 'arrayCount'
Thanks for any help,
::-Chase-::