2 years ago

#57836

test-img

serhii derkach

I can't see all elements of the array on the screen in Visual Studio

In my program I have 30 elements of the array. When I try to "COUT" them on the screen using "\t" between them - they stop on the 15th or so element. But if I use "endl" after each element - I can see them all. This problem happens only in Visual Studio on my computer. My teacher doesn't have the same problem and Dec C++ also shows all elements well with "\t". The code itself is pretty simple. Here is the code and screenshots.

#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <windows.h>
using namespace std;

int main()
{
    srand(time(NULL));
    int b;
    int c = 0;
    int d = 0;
    int array[30];
    for (;;)
    {
        d = 0;
        for (int i = 0;i < 30;i++)
        {
            b = rand() % 10;
            array[i] = b;
            if (array[i] == 2)b++;
            if (array[i] == 3)c++;
            if (array[i] == 1) d++;
        }
        if (d >= 3 && d <= 5 && b > c)
            break;
    }

    for (int i = 0;i < 30;i++)
    {
        cout << array[i] << "\t"; // if I switch to endl here - I will see all elements but I do want to understand the issue here with \t
    }
    cout << endl;
    cout << d << " " << b << " " << c;

    return 0;
}

c++

cout

visual-studio-2022

0 Answers

Your Answer

Accepted video resources