Create a statistical program which will allow the user to:
- Add new data
- See all data entered
- Find an item, to see whether it has been entered or not
- sum
- average
- maximum
- minimum
- Exit the program
These options must appear on a menu. Each option will be chosen by a number or a letter. The program must reserve space for a maximum of 1000 data, but keep count of how many data actually exist.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Statistics
{
class Program
{
static void Main(string[] args)
{
float[] numbers = new float[1000];
int count = 0;
float max = 0.0f, min = 0.0f, total = 0.0f, searchNumber = 0.0f;
bool found = false;
int option = 0;
do
{
Console.WriteLine("1. Add");
Console.WriteLine("2. Show");
Console.WriteLine("3. Search");
Console.WriteLine("4. Statistics");
Console.WriteLine("5. Exit");
option = Convert.ToInt32(Console.ReadLine());
if (option != 5)
{
switch (option)
{
case 1:
Console.WriteLine("Enter a number: ");
numbers[count] = Convert.ToSingle(Console.ReadLine());
max = numbers[count];
min = numbers[count];
total += numbers[count];
count++;
if (max < numbers[count])
max = numbers[count];
if (min > numbers[count])
min = numbers[count];
break;
case 2:
for (int i = 0; i < count; i++)
Console.WriteLine("{0} ", numbers[i]);
break;
case 3:
Console.WriteLine("Enter a number for search: ");
searchNumber = Convert.ToSingle(Console.ReadLine());
for (int i = 0; i < count; i++)
{
if (numbers[i] == searchNumber)
{
found = true;
Console.WriteLine("Number {0} found a amount of {1} ",i, numbers[i]);
}
}
if (!found)
{
Console.WriteLine("Not found");
found = false;
}
break;
case 4:
Console.WriteLine("Total data: {0}", count + 1);
Console.WriteLine("Sum: {0}", total);
Console.WriteLine("Average: {0}", total / (count + 1));
Console.WriteLine("Min number: {0}", min);
Console.WriteLine("Max number: {0}", max);
break;
default:
Console.WriteLine("Error, option 1-5");
break;
}
}
}
while (option != 5);
}
}
}
Post A Comment:
0 comments: