Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:21:06+00:00 2026-05-31T13:21:06+00:00

Basically, I’ve been taking a class on C programming, within that class we use

  • 0

Basically, I’ve been taking a class on C programming, within that class we use Linux machines to write and compile our code.

The program below is a part of our first assignment, I compiled it and ran it on Linux during the class with no issues, but having taken it home I cannot for the life of me get it to compile in Visual studio 2010 ultimate, or the eclipse IDE with the MinGW compiler.

Is there some typical issue with switching between the two operating systems that is causing my code to fail? or have I, being the rookie I am, written some ugly code that just won’t agree with VS 2010 or Eclipse?

Attempts to fix error messages that I have been getting from VS 2010 are it seems futile, so I’m leaning toward something essential missing from my computer. I have also set VS 2010 to compile C code so I dont think that is the issue.

errors from VS2010:

project1a.c(38): error C2143: syntax error : missing ‘;’ before ‘type’
project1a.c(41): error C2065: ‘i’ : undeclared identifier
project1a.c(44): error C2065: ‘userArray’ : undeclared identifier
project1a.c(44): error C2065: ‘i’ : undeclared identifier
project1a.c(44): error C2109: subscript requires array or pointer type
project1a.c(51): error C2065: ‘userArray’ : undeclared identifier

There are multiple instances of the ‘i’: undeclared identifier error inbetween these errors

#include <stdio.h>
#include <stdlib.h>

int n;
float total, avg;

int sumavg(void);

int main(void)
{
    //First time scan for the value to be assigned to n.
    printf("Hey, Enter a number or 999 to exit:> ");
    scanf("%d", &n);

    //if n == 999 then exit the program
    while(n != 999)
    {   
        //enter the sumavg function.
        sumavg();

        //Try to run the program again.
        printf("Hey, Enter a number or 999 to exit:> ");
        scanf("%d", &n);
    }

    //exit program. 
    return EXIT_SUCCESS;    
}

int sumavg(void)
{


    //Define a number that will be used for the array size.
    printf("Hey, now enter %d more numbers:>\n", n);

    //Define the size of array using the number assigned to the variable "n".
    int userArray[n], i;

    //Construct the array, one position at a time using the for loop.
    for (i = 0; i < n; i++)
    {
        //Assign a value to userArray[i] while i < n(the size of the array).
        scanf("%d", &userArray[i]);
    }

    //Calculate the sum by looping through each position in the userArray[i].
    for (i = 0; i < n; i++)
    {
        //Take the current position in the array and add it to the variable: "total"
        total += userArray[i];
    }

    //Calculate the average
    avg = total / n;

    //Print the sum followed by the average
    printf("Sum is: %.1lf\n", total);
    printf("The average is: %.1lf\n", avg);

    //reset total and avg in case future iterations are performed.
    total = 0;
    avg = 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:21:07+00:00Added an answer on May 31, 2026 at 1:21 pm

    The problem is that when compiling C code, MSVC does not support C99, only C90 (except maybe for a few library things). You’re using at least two C99 features that MSVC doesn’t support:

    • the big one is ‘variable length arrays’. Fixing this will generally require quite a bit of change to your code if you use them in any significant way. I’ll get back to this later.

    • the other one is declarations that occur after ‘normal’ statements

    C99 permits declarations to occur in a block after other kinds of statements; C90 doesn’t permit that – all declarations have to occur at the beginning of a block. So, then you declare userArray for example:

    int sumavg(void)
    {
        //Define a number that will be used for the array size.
        printf("Hey, now enter %d more numbers:>\n", n);
    
        //Define the size of array using the number assigned to the variable "n".
        int userArray[n], i;
    
        //...
    

    That is not permitted in C90 and MSVC complains about it when compiling in C mode (it won’t if compiling C++, since this kind of thing is supported in C++).

    To fix that problem move your declarations just after the start of a block:

    int sumavg(void)
    {
        //Define the size of array using the number assigned to the variable "n".
        int userArray[n], i;
    
        //Define a number that will be used for the array size.
        printf("Hey, now enter %d more numbers:>\n", n);
    
        //...
    

    Sometimes that will require you to rejigger initializations and what not.

    To fix the problem of using variable length arrays requires more work. In this case I think you can get by with declaring userArray as an int* and allocating the storage for it using malloc():

    int* userArray;
    
    userArray = malloc( sizeof(int) * n);
    

    A few other things:

    • since total and avg aren’t used outside of sumavg(), they should be local variables (initialized explicitly to 0)
    • you might want to pass n as an argument to sumavg() instead of using a global variable
    • you declare sumavg() as returning int, but don’t return anything. You should probably change the declaration to void
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have the following code: public class MyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
Basically I have some code to check a specific directory to see if an
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically I am writing a simple bit of code to increment every one second
Basically, I have a main page (parent page) with a link that opens up
Basically this function is meant to store the height value of the element that
basically I have a function that resizes elements accordingly with jquery triggering the function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.