CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Feb 2012
    Posts
    9

    How can I have the user input the data?

    I just want to know how I could have a user input the data instead of having it fixed such as in { 56, 76, 2, 4, 5 }.
    Im aware of the three codes here to input data but I dont know how to incorporate them in the code

    Code:
         // Returns an int value from the console
      public static int GetInt(String prompt) { 
        Console.Write(prompt);   
        return int.Parse(Console.ReadLine()); 
      }
    
            // Returns a double value from the console.
      public static double GetDouble(String prompt) {
        Console.Write(prompt);   
        return double.Parse(Console.ReadLine()); 
      }
    
            // Returns a char value from the console.
      public static char GetChar(String prompt) {
        Console.Write(prompt);   
        return Console.ReadLine()[0]; 
      }
    }
    Thanks



    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[][] region = new int[3][];    // scores
                region[0] = new int[5] { 56, 76, 2, 4, 5 };  //region1 5 stores
                region[1] = new int[3] { 83, 44, 14 };      //region2 3 stores
                region[2] = new int[2] { 34, 78, };      //region3 2 stores
                double sum;       // sum of the scores for each region
                for (int i = 0; i < region.Length; i++)
                {
                    sum = 0;
                    for (int j = 0; j < region[i].Length; j++)
                        sum += region[i][j];
                    Console.Write
                       ("The average for each region {0} is ", i);
                    Console.WriteLine((sum / region[i].Length).ToString("F1"));
                }   Console.ReadKey();
            }
        }
    }
    Last edited by mxrx81; February 16th, 2012 at 08:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured