Stores a sequence of temperatures in an array : Array : Collections Data Structure C# Source Code


Custom Search

C# Source Code » Collections Data Structure » Array »

 

Stores a sequence of temperatures in an array









    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// GetTemps.cs -- Stores a sequence of temperatures in an array
//
//                Compile this program with the following command line:
//                    C:>csc GetTemps.cs
//
namespace nsTemperatures
{
    using System;
    
    public class GetTemps
    {
        static public void Main ()
        {
            int [] Temps = new int [24]
                           {48, 47, 45, 45, 44, 45, 48, 54,
                            59, 64, 70, 75, 86, 92, 98, 101,
                            99, 97, 96, 91, 82, 70, 63, 55}
            ;
            for (int x = 0; x < 24; ++x)
            {
                while (true)
                {
                    Console.Write ("Enter the temperature for " + 
                                    (x == 0 ? "Midnight"
                                    : (x == 12 ? "Noon"
                                    : ((x < 12 ? x.ToString() + " a."
                                    : ((x - 12).ToString() + " p."))
                                    + "m."))) + ": "
                                  );
                    try
                    {
                        Temps[x] = Convert.ToInt32 (Console.ReadLine ());
                        break;
                    }
                    catch
                    {
                         Console.WriteLine ("\r\nPlease enter a number value.");
                    }
                }
            }
            Console.WriteLine ("The daily temperature report:");
            for (int x = 0; x < 24; x += 4)
            {
                Console.WriteLine ("{0,4:D4} : {1,3:D}\t{2,4:D4}: {3,3:D}\t" +
                                   "{4,4:D4}: {5,3:D}\t{6,4:D4}: {7,3:D}",
                                   x * 100, Temps[x],
                                   (x + 1) * 100, Temps[x + 1],
                                   (x + 2) * 100, Temps[x + 2],
                                   (x + 3) * 100, Temps[x + 3]);
            }
        }
    }
}



           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» Array