[Solved] How to print 3 different values per line in C++


Try something more like this:

cout << "Please enter a number to search: ";
cin >> n;

out << endl;
out << "Occasions during the year when there were three consecutive days where the temperature went above " << n << " are:" << endl;

int firstday, numdays = 0;

for (int x = 0; x < 366; ++x)
{
    in >> minimum[x];
    in >> maximum[x];

    if (maximum[x] > n)
    {
        ++numdays;

        if (numdays == 1)
            firstday = x;
        else if (numdays == 3)
        {
            out << "Days: " << firstday << ", " << firstday+1 << ", " << firstday+2 << endl;
            numdays = 0;
        }
    }
    else
        numdays = 0;
}

Alternatively:

cout << "Please enter a number to search: ";
cin >> n;

out << endl;
out << "Occasions during the year when there were three consecutive days where the temperature went above " << n << " are:" << endl;

for (int x = 0; x < 366; ++x)
{
    in >> minimum[x];
    in >> maximum[x];
}

for (int x = 0; x < 366-2; ++x)
{
    if (maximum[x] > n)
    {
        int firstday = x;
        int numdays = 1;

        for (int y = 1; y < 3; ++y)
        {
            if (maximum[x+y] > n)
                ++numdays;
            else
                break;
        } 

        if (numdays == 3)
            out << "Days: " << firstday << ", " << firstday+1 << ", " << firstday+2 << endl;

        x += (numdays-1);
    }
}

1

solved How to print 3 different values per line in C++