Tips List



Tips List

This simple command line C# program asks you to enter 7 tips. It then puts them into an array an subtracts each number from the average of all the numbers. Finally it displays them in US currency format.

Here's the code!

                            using System;
                            namespace TipsList
                            {
                                class TipsList
                                {
                                    static void Main(string[] args)
                                    {
                                        double[] tips = new double[7];
                                        int x;

                                        for (x = 0; x < tips.Length; ++x)
                                        {
                                            Console.Write("Enter tip {0}: ", x + 1);
                                            tips[x] = Convert.ToDouble(Console.ReadLine());
                                        }

                                        double avg = (tips[0] + tips[1] + tips[2] + tips[3] + tips[4] + tips[5] + tips[6]) / tips.Length;

                                        for (x = 0; x < tips.Length; ++x)
                                        {
                                            double difference = tips[x] - avg;
                                            Console.WriteLine("{0} {1}", tips[x].ToString("C2"), Math.Abs(difference).ToString("C"));
                                        }
                                        Console.ReadLine();
                                    }
                                }
                            }