0

So I know that turbo C++ is an old compiler, but that is what our instructor told us to use. I keep getting Constant Expression Required, but on the other compiler it works just as fine.

`

#include <stdio.h>

int main() {
    int numberV;
    
    printf("How many numbers: ");
    scanf("%d",&numberV);
    
    int numbers[numberV]={};
    
    for (int i=1;i<=numberV;i++){
        printf("Enter value [%d]: ",i);
        int n;
        scanf("%d",&n);
        numbers[i] = n;
    
    }

for (i=1; i<=numberV; i++)
        printf("%d,",numbers[i]);
    return 0;

}


PROOF THAT IT WORKS ON OTHER COMPILER

This is the code it works fine. I can store arrays, I can print it out fine and it loops perfectly.

but when I transfer this to Turbo C++, it shows CONSTANT EXPRESSION REQUIRED and Expression Required on this part: int numbers[numberV]={};

Code on Turbo C++

{} is a null set right? So can I put a zero in there or is there any other way I can translate this into the Turbo C++ compiler?

Suwaaaa
  • 11
  • 1
  • 4
    Turbo-C++ is completely outdated (by multiple decades) and you shouldn't expect it to conform to present C++ (it uses a dialect from before standardization). But in this case it is agreeing with the C++ standard. The size of an array must be a compile-time constant. You can't read the size from the user and make an array of that size. Other compilers are allowing it only as an extension to the language. Use `std::vector` instead of an array if you need a dynamically-sized array. – user17732522 Nov 06 '22 at 01:48

0 Answers0