0
#include <stdio.h>

int main() {
    int i, count;
    int sum = 0;
    scanf_s("%d", &count);
    int num[count];
    for (i = 1; i <= count; i++) {
        printf("Enter %d number: \n", i);
        scanf_s("%d", &num[i]);
        sum = sum + num[i];
    }
    int average = sum / count;
    printf("Average = %d", average);
}

Getting error while running this code in visual studio 17. How to write int num[count];

  • 2
    There's nothing in your code that is specific to C++, it's all plain C. And that's the problem, because in C it's allowed with [variable-length arrays](https://en.wikipedia.org/wiki/Variable-length_array) but [C++ doesn't have them](https://stackoverflow.com/questions/1887097/why-arent-variable-length-arrays-part-of-the-c-standard). – Some programmer dude Dec 08 '22 at 07:00
  • 1
    So what resources are you using to learn programming? Do they really claim to teach you C++, or C? – Some programmer dude Dec 08 '22 at 07:01
  • I am learning C, added C++ Tag mistakenly – Sukhpreet Kaur Plaha Dec 13 '22 at 09:40
  • Maybe I should have started with this, but please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). What kind of "error" do you get? A build error? A runtime error or crash? Unexpected results? – Some programmer dude Dec 13 '22 at 12:25
  • And you might be learning C, but the error seems to come from the C++ compiler. What is the name of your source file? Does it end in `.c` or in `.cpp`? – Some programmer dude Dec 13 '22 at 14:13

0 Answers0