Pretty stumped on why I am getting so many errors trying to get this to work, the reason terminalArray is not declared is because this is a function, terminalArray was declared before main. Any help will be greatly appreciated!

int histArray[10];
int i;
int j;

while (terminalArray >= 1 && terminalArray < 99)
if (terminalArray >= 1 && terminalArray < 9;) 
    {histArray[0]++};
else if (terminalArray >= 10 && terminalArray < 19;) 
    {histArray[1]++};
else if (terminalArray >= 20 && terminalArray < 29;) 
    {histArray[2]++};
else if (terminalArray >= 30 && terminalArray < 39;) 
    {histArray[3]++};
else if (terminalArray >= 40 && terminalArray < 49;) 
    {histArray[4]++};
else if (terminalArray >= 50 && terminalArray < 59;) 
    {histArray[5]++};
else if (terminalArray >= 60 && terminalArray < 69;) 
    {histArray[6]++};
else if (terminalArray >= 70 && terminalArray < 79;) 
    {histArray[7]++};
else if (terminalArray >= 80 && terminalArray < 89;)
    {histArray[8]++};
else if (terminalArray >= 90 && terminalArray < 99;) 
    {histArray[9]++};

cout << "1-9: ";
for (j = 0; j < histArray[0]; j++)
{
    cout << "*" << endl;
}

cout << "10-19: ";
for (j = 0; j < histArray[1]; j++)
{
    cout << "*" << endl;
}

cout << "20-29: ";
for (j = 0; j < histArray[2]; j++)
{
    cout << "*" << endl;
}

cout << "30-39: ";
for (j = 0; j < histArray[3]; j++)
{
    cout << "*" << endl;
}

cout << "40-49: ";
for (j = 0; j < histArray[4]; j++)
{
    cout << "*" << endl;
}

cout << "50-59: ";
for (j = 0; j < histArray[5]; j++)
{
    cout << "*" << endl;
}

cout << "60-69: ";
for (j = 0; j < histArray[6]; j++)
{
    cout << "*" << endl;
}

cout << "70-79: ";
for (j = 0; j < histArray[7]; j++)
{
    cout << "*" << endl;
}

cout << "80-89: ";
for (j = 0; j < histArray[8]; j++)
{
    cout << "*" << endl;
}

cout << "90-99: ";
for (j = 0; j < histArray[9]; j++)
{
    cout << "*" << endl;
}

return 0; 

Recommended Answers

All 8 Replies

use opening and ending brackets for the while loop also why are there semicolons before the end of the parentheses' nested if conditions

other than that could you post those error messages here and maybe some important parts of the code where an error could be found like the main function

Thanks for the reply, dont know what I was doing with those semicolons and the brackets :S
I am getting the same set of three errors for the while loop and every "if" and "else if" statement inside.
The array Terminal Array contains 12 values inputted by the user in another function earlier in the program, I wont post the rest of my code as it is incredibly long and im not sure it is relevant to this problem.
Here are the errors:

error C2040: '>=' : 'int [12]' differs in levels of indirection from 'int'
error C2446: '<' : no conversion from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

Sorry forgot to give you my new code:

int histArray[10];
int i;
int j;

while (terminalArray >= 1 && terminalArray < 99)
{
if (terminalArray >= 1 && terminalArray < 9) 
{
    histArray[0]++;
}
else if (terminalArray >= 10 && terminalArray < 19) 
{   
    histArray[1]++;
}
else if (terminalArray >= 20 && terminalArray < 29) 
{
    histArray[2]++;
}
else if (terminalArray >= 30 && terminalArray < 39) 
{
    histArray[3]++;
}
else if (terminalArray >= 40 && terminalArray < 49) 
{
    histArray[4]++;
}
else if (terminalArray >= 50 && terminalArray < 59) 
{
    histArray[5]++;
}
else if (terminalArray >= 60 && terminalArray < 69) 
{
    histArray[6]++;
}
else if (terminalArray >= 70 && terminalArray < 79) 
{
    histArray[7]++;
}
else if (terminalArray >= 80 && terminalArray < 89)
{
    histArray[8]++;
}
else if (terminalArray >= 90 && terminalArray < 99) 
{
    histArray[9]++;
}
}

cout << "1-9: ";
for (j = 0; j < histArray[0]; j++)
{
    cout << "*" << endl;
}

cout << "10-19: ";
for (j = 0; j < histArray[1]; j++)
{
    cout << "*" << endl;
}

cout << "20-29: ";
for (j = 0; j < histArray[2]; j++)
{
    cout << "*" << endl;
}

cout << "30-39: ";
for (j = 0; j < histArray[3]; j++)
{
    cout << "*" << endl;
}

cout << "40-49: ";
for (j = 0; j < histArray[4]; j++)
{
    cout << "*" << endl;
}

cout << "50-59: ";
for (j = 0; j < histArray[5]; j++)
{
    cout << "*" << endl;
}

cout << "60-69: ";
for (j = 0; j < histArray[6]; j++)
{
    cout << "*" << endl;
}

cout << "70-79: ";
for (j = 0; j < histArray[7]; j++)
{
    cout << "*" << endl;
}

cout << "80-89: ";
for (j = 0; j < histArray[8]; j++)
{
    cout << "*" << endl;
}

cout << "90-99: ";
for (j = 0; j < histArray[9]; j++)
{
    cout << "*" << endl;
}

return 0;

A more compact version of your current code (untested)

int histArray[10] = {0};
int minValue;
int maxValue;

while (terminalArray >= 1 && terminalArray <= 99)
{
    minValue = 1;
    maxValue = 9;

    for (int i = 0; i < 10; i++)
    {
        if (terminalArray >= minValue && terminalArray <= maxValue)
        {
            ++histArray[i];
        }

        i == 0 ? minValue += 9 : minValue += 10;
        maxValue += 10;
    }
}

minValue = 1;
maxValue = 9;

for (int i = 0; i < 10; i++)
{
    cout << "\"" << minValue << "-" << maxValue << ": " << histArray[i] << "\"" << endl;
    i == 0 ? minValue += 9 : minValue += 10;
    maxValue += 10;
}

cin.get();

return 0;

Cheers for that mate, looks much better, although I am still getting the errors I stated above, do you know why that is? Is it because of the terminalArray already containing twelve values from another fuction earlier on in the program?

What is the declaration of terminalArray?

Try this:

    // int terminalArray[12] = {0};
    int histArray[10] = {0};
    int minValue;
    int maxValue;

    for (int j = 0; j < 12; j++)
    {
        minValue = 1;
        maxValue = 9;

        for (int i = 0; i < 10; i++)
        {
            if (terminalArray[j] >= minValue && terminalArray[j] <= maxValue)
            {
                ++histArray[i];
            }

            i == 0 ? minValue += 9 : minValue += 10;
            maxValue += 10;
        }
    }

cheers mate works a dream!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.