Code Woks in sololearn but not in visuel studio c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code Woks in sololearn but not in visuel studio c++

hey,i have the problem that my code works in sololearn but not in visual studios. what am I doing wrong? Thanks in advance #include <iostream> using namespace std; int main() { int n; cin >> n; //size of the array //your code goes here int nums[n]; int s = 0; for (int d = 0; d < n; d++) { cin >> s; nums[d] = s; } int max = nums[0]; for (int i = 0; i < n; i++) { if (nums[i] > max) { max = nums[i]; } } cout << max; return 0; } Severity Code Description Project File Line Suppression State Error C2131 expression did not evaluate to a constant Project1 D:\DEV\Basics\Basics\Project1\MAX(Arr).cpp 8 Severity Code Description Project File Line Suppression State Error C3863 array type 'int [n]' is not assignable Project1 D:\DEV\Basics\Basics\Project1\MAX(Arr).cpp 13

31st Mar 2022, 8:43 PM
Mj Yoo
7 Answers
+ 2
To be more compatible, you can use dynamic memory allocation approach for creating the array <num>, given a size. https://www.sololearn.com/learn/CPlusPlus/1632/
1st Apr 2022, 6:13 PM
Ipang
+ 2
You are using VLA which is not an official feature of the C++ language. Some compilers have it as extension but it doesn't mean a VLA based code be guaranteed to run (compilable) in any compiler, that includes one that came with (or as extension in) VSC. https://en.m.wikipedia.org/wiki/Variable-length_array https://stackoverflow.com/questions/14075194/variable-length-arrays-vla-in-c-and-c
31st Mar 2022, 8:58 PM
Ipang
+ 1
And Soloearn uses Gcc 10.2 compiler... https://www.sololearn.com/discuss/2856118/?ref=app
31st Mar 2022, 9:06 PM
Jayakrishna 🇮🇳
+ 1
Thanks everybody for your responses
3rd Apr 2022, 10:29 PM
Mj Yoo
0
Use CODE BLOCKS editor for c++
1st Apr 2022, 7:40 AM
Ardavan Eskandari
Ardavan Eskandari - avatar
0
🥺🥺how can i make it run on VS? Just need to install Gcc on visuell studios? Does every compiler have a diffrent syntax then ?
1st Apr 2022, 5:07 PM
Mj Yoo