0
if(company[i][j] < 0)
{
    loss = loss++;
}
else

//Im trying to Get the number of losses and not the actual input numbers"for example loike 1 loss, 2 loss etc

3
Contributors
6
Replies
23
Views
4 Years
Discussion Span
Last Post by maurice.tracey.7
0

The only thing I see is that loss = loss++; is redundant. loss++; does the same thing. Other than that if company is an array of int, double, etc. and any value less than 0 indicates a loss, 2 loops will iterate through the array and get the total you're looking for. Something like:

for(int i = 0; i < row_size; i++)
{
    for(int j = 0; j < column_size; j++)
    {
        if(company[i][j] < 0)
        {
            loss++;
        }
    }
}
cout << loss << " losses\n";

row_size and column_size are the number of elements in each part of the array.

On a side note thinking in terms of rows and columns can make it easier for some people to grasp this kind of array structure.

Edited by tinstaafl

0

ok thanks i actually got it, all i was missing was a statement like loss =0; fo each like it would just pick up the losses and increment back to 0 each time, instead of continually incrementing

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.