/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello Election");
Election election = new Election();
election.Test();
}
}
using System;
class Election
{
//صفات
private string[] Names = { "Adan ", "Yomna", "Ahmad", "Omre ", "jmal ", "Ehab " };
private int[] Counter;
private int numVotes;
private int CurrentVoter;
//بناء
public Election()
{
Counter = new int[6];
for (int i = 0; i < Counter.Length; i++)
Counter[i] = 0;
numVotes = 3;
Console.Write("Please enter # of Voters:");
numVotes = int.Parse(Console.ReadLine());
CurrentVoter = 0;
}
//عمليات
public void Print()
{
for (int k = 0; k < Names.Length; k++)
{
//Console.WriteLine("{0}.{1}: {2}", k, Names[k], Counter[k]);
Console.WriteLine(" | {0}.{1}: {2}", k, Names[k], Counter[k]);
}
}
private void Menu()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine();
Console.WriteLine(" |=================================================");
Console.WriteLine(" |");
Console.WriteLine(" |Welcome to Election 10 1 {0}", System.DateTime.Now);
Console.WriteLine(" |");
this.Print();
Console.WriteLine(" |");
Console.WriteLine(" |");
Console.WriteLine(" |=================================================");
Console.WriteLine();
//Console.WriteLine(" Press any key to Continue...");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
}
private void Winner()
{
int Max = this.Counter[0];
int Max_index = 0;
for (int i = 1; i < this.Counter.Length; i++)
{
if (this.Counter[i] > Max)
{
Max = this.Counter[i];
Max_index = i;
}
}
Console.WriteLine("Winner is: {0} with {1} Points!", this.Names[Max_index], this.Counter[Max_index]);
Console.WriteLine("More than can have the same number of Points!");
}
private void StudentsVote()
{
for (int j = 0; j < this.numVotes; j++)
{
this.CurrentVoter = j;
OneStudentVote();
}
}
private void OneStudentVote()
{
Menu();
Console.WriteLine();
Console.Write("student {0}/{1}:",this.CurrentVoter+1, this.numVotes);
Console.Write(" Please Vote 0-{0}:", Names.Length - 1);
int vote = int.Parse(Console.ReadLine());
if (vote > Names.Length - 1 || vote < 0)
Console.WriteLine("Bad vote. will NOT be Counted!");
else
this.Counter[vote]++;
}
public void Test()
{
Menu();
StudentsVote();
Menu();
Console.WriteLine("Election - Voting Completed");
Winner();
}
}