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 909349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:51:48+00:00 2026-05-15T16:51:48+00:00

I have written the following code in an effort to try and compute the

  • 0

I have written the following code in an effort to try and compute the values down there below, but all my arrays do not work; especially the ones in the for loops. Can someone help teach me how to declare an array inside a loop? They keep showing errors like “Did you miss declaring a new object?”

Thanks

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public class seasonal
        {
            public float mTotal;
            public float movingAverage;
            public int y;

            public char quarter;
            public char ssq;
            public int rank;
            public float forecast;
            public float centralMovingAverage;
            public float cmTotal;
            public float sSeasonal;
        }
        public static int i;
        public static int j;
        public static int k = 0;
        public static int n;

        static void Main(string[] args)
        {
            int x; int r; int m; int c; int u = 0;


            seasonal temp = new seasonal();

            int n1; int n2; int n3; int n4; int sumr1 = 0; int sumr2 = 0; int sumr3 = 0; int sumr4 = 0;
            float h; float ss; float sum; float sums1 = 0; float sums2 = 0; float sums3 = 0; float sums4 = 0; float tsums;

            Console.WriteLine("Enter the no. of observations");
            string nObservations = Console.ReadLine();
            n = Convert.ToInt32(nObservations);

            seasonal[] seasonal = new seasonal[n];
            seasonal[] s = new seasonal[n];

            for (i = 0; i < n; i++)
            {
                Console.Write("{0:D}:", (i+1) );
                string value = Console.ReadLine();
                int observation = Convert.ToInt32(value);

                seasonal thisSeasonal = new seasonal();
                thisSeasonal.y = observation;

                seasonal[i] = thisSeasonal;

                if (i>=0 && i<3)
                {
                    seasonal[i].quarter = '1';                    
                }
                if (i>=3 && i<6)
                {
                    seasonal[i].quarter = '2';
                }
                if (i>=6 && i<9)
                {
                    seasonal[i].quarter = '3';
                }
                if (i>=9 && i<12)
                {
                    seasonal[i].quarter = '4';
                }
                if (i>12)
                {
                    r = i % 12;
                    if (r>=0 && r<3)
                    {
                        seasonal[i].quarter = '1';
                    }
                    if (r>=3 && r<6)
                    {
                        seasonal[i].quarter = '2';
                    }
                    if (r>=6 && r<9)
                    {
                        seasonal[i].quarter = '3';
                    }
                    if (r>=9 && r<12)
                    {
                        seasonal[i].quarter = '4';
                    }
                }

                for (i = k; i < n-3; i++)
                {
                    sum = 0;
                    for (j = u+k; j < 4+k; j++)
                    {
                        sum += seasonal[j].y;
                        seasonal[i].mTotal = sum;
                        seasonal[i].movingAverage = seasonal[i].mTotal / 4;
                        Console.Write("{0:f}", seasonal[i].movingAverage);
                        k++;
                    }
                }

                for ( i = 0; i < (n-4); i++)
                {
                    ss = 0;

                    for (j = 0; j < (2+i); j++)
                    {
                        ss += seasonal[j].movingAverage;
                    }

                    seasonal[i].cmTotal = ss;
                    seasonal[i].centralMovingAverage = seasonal[i].cmTotal / 2;

                    seasonal[i].sSeasonal = (seasonal[i+2].y)/(seasonal[i].centralMovingAverage);

                    if (i == 0 || i % 4 == 0)
                    {
                        seasonal[i].ssq = '3';
                    }
                    if (i == 1 || i % 4 == 1)
                    {
                        seasonal[i].ssq = '4';
                    }
                    if (i == 2 || i % 4 == 2)
                    {
                        seasonal[i].ssq = '1';
                    }
                    if (i == 3 || i % 4 == 3)
                    {
                        seasonal[i].ssq = '2';
                    }

                    Console.Write("\n{0:f}", seasonal[i].centralMovingAverage);
                    Console.Write("\n {0:f}", seasonal[i].sSeasonal);
                }
            }

            for (m= 0; m < n; m++)
            {
                s[m] = seasonal[m];
            }

            for ( i = 0; i < (n-5); i++)
            {
                for ( j = 0; j < (n-4); j++)
                {
                    if (s[i].sSeasonal > s[j].sSeasonal)
                    {
                        temp = s[i];
                        s[i] = s[j];
                        s[j] = temp;
                    }
                }
            }

            for ( k = 0; k < (n-4); k++)
            {
                s[k].rank = k + 1;
                Console.Write("\n\t {0:D}", s[k].rank);
            }

            for ( i = 0; i < (n-4); i++)
            {
                if (s[i].ssq == '1')
                {
                    sumr1 += s[i].rank;
                    sums1 += s[i].sSeasonal;
                    //n1 ++;
                }
                if (s[i].ssq == '2')
                {
                    sumr2 += s[i].rank;
                    sums2 += s[i].sSeasonal;
                    //n2++;
                }
                if (s[i].ssq == '3')
                {
                    sumr3 += s[i].rank;
                    sums3 += s[i].sSeasonal;
                    //n3++;
                }
                if (s[i].ssq == '4')
                {
                    sumr4 += s[i].rank;
                    sums4 += s[i].sSeasonal;
                    //n4++;
                }
            }
            tsums = ((sums1/4)+(sums2/4)+(sums3/4)+(sums4/4));
            Console.Write("\n\n\n{0:f}",tsums);
            Console.Write("\n\n\n\n\n{0:D}",sumr1);
            Console.Write("\n\n\n\n{0:D}",sumr2);
            Console.Write("\n\n\n\n{0:D}",sumr3);
            Console.Write("\n\n\n\n\n{0:D}",sumr4);
            Console.Write("\n{0:f}",sums1/4);
            Console.Write("\n\n{0:f}",sums2/4);
            Console.Write("\n\n{0:f}",sums3/4);
            Console.Write("\n\n{0:f}",sums4/4);
            Console.Write("\n{0:f}",((sums1/4)/tsums)*4);
            Console.Write("\n\n{0:f}",((sums2/4)/tsums)*4);
            Console.Write("\n\n{0:f}",((sums3/4)/tsums)*4);
            Console.Write("\n\n{0:f}",((sums4/4)/tsums)*4);

        }
    }
}
  • 1 1 Answer
  • 2 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-15T16:51:49+00:00Added an answer on May 15, 2026 at 4:51 pm

    You need to initialise the objects in your arrays:

    Seasonal[] seasonal = new Seasonal[n];
    for (int l = 0; l < seasonal.Length; l++)
    {
        seasonal[l] = new Seasonal();
    }
    Seasonal[] s = new Seasonal[n];
    for (int l = 0; l < s.Length; l++)
    {
        s[l] = new Seasonal();
    }
    

    This only solves the initialisation problem, though. You may want to look at naming conventions for readability, and then the index off by 1 you’ll experience at roughly line 105.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code. But it is removing only &nbsp; not <br>
I have written following code to pass File1 variable to Javascript, but its not
i have written the following code: As you can see there is a for
I have written Following code which will apply color to all static text in
I have written following code for the client of RMI. But getting java.rmi.ConnectException: Connection
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
i have written the following code class Program { static void Main(string[] args) {
I have written the following code, CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(@C:\Users\XXX\Desktop\Backup1\Project\ReportsFolder\ReportSalesInvoice.rpt); Report works
I have written a following code to get just the file name without extension

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.