0

I have just starting and i am new to programming. I am doing an exercise where i have to ask the user for the rainfall for each month over a period of years of his or hers own choosing.The program needs to show the total rainfall for the year and the average rainfall per month. I am stuck on 2 things,

1st is how do i get the loop to recognize the amount of the years the user has entered (eg): if he or she enters 2 years that after year one year the 2nd starts.At the minute it is only running for 1 year.

2nd problem i have is,at the end of the year i can't seem to get the totals the user has entered for each month to display.How can i get these from the array.I have attached my coding below. Any help i could get on this is very much appreciated,thanks

namespace RainFall
{
    class Program
    {
        static void Main(string[] args)
        {
            int Numyears = 0;
            //int Month = 12;
            double Rainfall = 0.0;
            double avrRainfall = 0.0;
            string[] Month = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 

            Console.WriteLine("please enter number of years");
            Numyears = int.Parse(Console.ReadLine());

            while(Numyears <= 0)
            {  
                Console.WriteLine("Minimum number of years is 1 Please re-enter");
                Numyears = int.Parse(Console.ReadLine());
            }

            for(int i = 0; i < Month.Length; i ++)
            { 
                Console.WriteLine(" Enter inches of rainfall for {0}", Month[i]);
                Console.ReadLine(); 
            }

            for (int i = 0;i < Month.Length; i++)
            {
                Console.WriteLine(" {1} Total;", i + 1, Month[i]);
            }
        }
    }
}
2
  • Try to repost your code. You didn't do it correctly Commented Dec 2, 2015 at 17:42
  • Never assign a primitive type name the same as the Namespace name. Commented Dec 2, 2015 at 17:51

1 Answer 1

0

So, being that this is a learning assignment, it wouldn't do anyone any good to just give you the answers, but I would like to help by providing some things to consider/ask yourself:

  • Think some more about your loops, and what you are expecting from the user. Currently, no matter what the input is for years, you are looping only for the length of the array that has the names of the months (*which will always be the same length).
  • When you ask the user to input the rainfall for each month in the months array, where are these numbers being stored (and does it make sense)?
  • Once you figure out the above, you will definitely need more logic to calculate and display the average/total rainfall.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you for your input, i will work off the points you have given and try figure this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.