using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArraysAndLoops2
{
class Program
{
///
/// This program will create an array
/// populate and array
/// Display it
/// sum and average the contents
///
static void Main(string[] args)
{
Program p = new Program();
string choice="y";
while (choice != "n" && choice != "N")
{
p.CreateArray();
p.ParallelArrays();
Console.WriteLine("Do you want enter more payments? Y/N");
choice = Console.ReadLine();
}
Console.ReadKey();
}
private void CreateArray()
{
//double[] payments = new double[5];
//payments[0] = 234.5;
//payments[1] = 45.6;
//payments[2] = 100;
//payments[3] = 37.98;
//payments[4] = 223;
//int[] ray;
//ray = new int[] { 45, 2, 3, 7, 22 };
Console.WriteLine("How many payments do you want to enter");
int number = int.Parse(Console.ReadLine());
double[] payments = new double[number];
for (int i = 0; i < number; i++)
{
Console.WriteLine(payments[i]);
}//end for
FillArray(payments, number);
}//end create array
private void FillArray(double[] paymnts, int size)
{
for (int i = 0; i < size; i++)
{
Console.WriteLine("Enter Payment");
paymnts[i] = double.Parse(Console.ReadLine());
}// end for
DisplayArray(paymnts, size);
}//end of Fill array
private void DisplayArray(double[] pmts, int size)
{
Console.WriteLine("************************\n");
//Console.Clear();
for (int i = 0; i < size; i++)
{
Console.WriteLine(pmts[i]);
}//end for
SumAndAverage(pmts, size);
}//end Display
private void SumAndAverage(double[] pay, int size)
{
double total = 0;
for (int i = 0; i < size; i++)
{
total += pay[i]; //total=total + pay[i] -= *= %= /=
}
Console.WriteLine("The total is {0}", total);
double average = total / pay.Length;
Console.WriteLine("the average is {0}", average);
}//end sum and average
private void ParallelArrays()
{
int[] myArray1 = new int[] { 2, 3, 54, 6, 8 };
int[] myArray2 = new int[] { 3, 5, 2, 12, 4 };
for (int i = 0; i < myArray1.Length; i++)
{
Console.WriteLine(myArray1[i] * myArray2[i]);
}
}
}//end class
}
Tuesday, October 18, 2011
Morning Arrays and loops
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment