The Application has to display temperatures for five cities. I can't get the lowest and highest temperature columns to display. I got the first three columns for the temperature readings to display along with the average temperature column, but can't get the fourth temperature reading column to display. In addition, I can't get the area average label to display the area average. Any ideas?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab8practice1
{
public partial class Form1 : Form
{
string[] strCities = { "Troy",
"West Bloomfield",
"Farmington Hills",
"Brighton",
"Canton"};
int[,] intTemperatures = new int[5, 3];
public Form1()
{
InitializeComponent();
}
private void btnAddTemperature_Click(object sender, EventArgs e)
{
try
{
if (cmbCities.SelectedIndex >= 0 && cmbCities.SelectedIndex <= 4)
{
if (intTemperatures[cmbCities.SelectedIndex, (int)nudReading.Value -1] == 0)
{
intTemperatures[cmbCities.SelectedIndex, (int)nudReading.Value - 1] = Int32.Parse(txtTemperature.Text);
}
else
{
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show("Modify Temperature?", "Temperature already exists!", buttons);
if (result == System.Windows.Forms.DialogResult.Yes)
{
intTemperatures[cmbCities.SelectedIndex, (int)nudReading.Value - 1] = Int32.Parse(txtTemperature.Text);
}
}
displayTemperatures();
}
else
{
MessageBox.Show("Select a city!");
}
}
catch (FormatException)
{
MessageBox.Show("Temperatures must be whole numbers!");
}
}
private void displayTemperatures()
{
string strCities;
lstTemperatures.Items.Clear();
double[] dblAverages = new double[5];
int intNonBlank = 0;
double dblNonBlank = 0.0;
int intMin = 150, intMax = 0, intTotal = 0;
for (int g = 0; g <= 4; g++)
{
intNonBlank = 0;
for (int d = 0; d <= 2; d++)
{
if (intTemperatures[g, d] != 0)
{
dblAverages[g] += intTemperatures[g, d];
intNonBlank++;
}
}
if (intNonBlank != 0)
{
dblAverages[g] /= intNonBlank;
}
}
for (int g = 0; g <= 4; g++)
{
for (int d = 0; d <= 2; d++)
{
if (intTemperatures[g, d] != 0)
{
intTotal += intTemperatures[g, d];
dblNonBlank++;
}
if (intTemperatures[g, d] < intMin && intTemperatures[g, d] != 0)
{
intMin = intTemperatures[g, d];
}
if (intTemperatures[g, d] > intMax)
{
intMax = intTemperatures[g, d];
}
}
}
for (int g = 0; g <= 4; g++)
{
strCities = " ";
for (int d = 0; d <= 2; d++)
{
if (intTemperatures[g, d] == 0)
{
strCities += " ";
}
else
{
if (intTemperatures[g, d] == 103)
{
strCities += intTemperatures[g, d] + " ";
}
else
{
strCities += intTemperatures[g, d] + " ";
}
}
}
if (dblAverages[g] == 0)
{
strCities += " ";
}
else
{
if (dblAverages[g] == 140)
{
strCities += dblAverages[g].ToString("f2") + " ";
}
else
{
strCities += dblAverages[g].ToString("f2") + " ";
}
}
lstTemperatures.Items.Add(strCities);
lblAreaAverage.Text = dblAverages.ToString("f2");
}
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i <= 4; i++)
{
cmbCities.Items.Add(strCities[i]);
lstCities.Items.Add(strCities[i]);
}
}
}
}
Related
I tried to create a small calculator and everything worked just fine. I could do every operation without an error. Then I tried to improve some things and add some.
Out of a sudden the original Part does not work anymore and i get the Error:[ System.FormatException: "Input string was not in a correct format." ] every time i try to substract, multiply or divide.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Calculator_V2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
answer.Text = Calculate(textBox.Text);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string s_button = sender.ToString();
textBox.Text = textBox.Text + s_button.Substring(s_button.Length - 1);
}
public string Calculate(string text)
{
double finalAnswer = AddAndSubstract(text);
return finalAnswer.ToString();
}
public double AddAndSubstract(string text1)
{
string[] text = text1.Split('-');
List<string> textList = new List<string>();
for (int i = 0; i < text.Length; i++)
{
textList.Add(text[i]);
if (i != text.Length - 1)
{
textList.Add("-");
}
textList.Add("-");
}
for (int i = 0; i < textList.Count; i++)
{
if (textList[i].Contains('+') && textList[i].Length > 1)
{
string[] testPart = textList[i].Split('+');
textList.RemoveAt(i);
for (int j = testPart.Length - 1; j >= 0; j--)
{
textList.Insert(i, testPart[j]);
if (j != 0)
{
textList.Insert(i, "+");
}
}
}
}
double total;
if (textList[0].Contains("*") || textList[0].Contains("/"))
{
total = DivideAndMultiply(textList[0]);
return total;
}
else
{
total = Convert.ToDouble(textList[0]);
for (int i = 2; i < textList.Count; i += 2)
{
if (textList[i - 1] == "-")
{
total = total - DivideAndMultiply(textList[i]);
}
else if (textList[i - 1] == "+")
{
total = total + DivideAndMultiply(textList[i]);
}
}
return total;
}
}
public double DivideAndMultiply(string text1)
{
string[] text = text1.Split('*');
List<string> textList = new List<string>();
for (int i = 0; i < text.Length; i++)
{
textList.Add(text[i]);
if (i != text.Length - 1)
{
textList.Add("*");
}
textList.Add("*");
}
for (int i = 0; i < textList.Count; i++)
{
if (textList[i].Contains('/') && textList[i].Length > 1)
{
string[] testPart = textList[i].Split('/');
textList.RemoveAt(i);
for (int j = testPart.Length - 1; j >= 0; j--)
{
textList.Insert(i, testPart[j]);
if (j != 0)
{
textList.Insert(i, "/");
}
}
}
}
double total = Convert.ToDouble(textList[0]);
for (int i = 2; i < textList.Count; i += 2)
{
if (textList[i - 1] == "/")
{
total = total / Convert.ToDouble(textList[i]);
}
else if (textList[i - 1] == "*")
{
total = total * Convert.ToDouble(textList[i]);
}
}
return total;
}
private void Button_Click_C(object sender, RoutedEventArgs e)
{
double finalAnswer = 0;
answer.Text = "";
textBox.Text = "";
}
private void Button_Click_zahl(object sender, RoutedEventArgs e)
{
string s_button = sender.ToString();
textBox.Text = textBox.Text + s_button.Substring(s_button.Length - 1);
}
private void Button_Click_equals(object sender, RoutedEventArgs e)
{
answer.Text = RemoveBrackets(textBox.Text);
}
public string RemoveBrackets(string text)
{
while (text.Contains('(') && text.Contains(')'))
{
int openIndex = 0;
int closeIndex = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == '(')
{
openIndex = i;
}
if (text[i] == ')')
{
closeIndex = i;
text = text.Remove(openIndex,closeIndex-openIndex +1).Insert(openIndex,ResolveBrackets(openIndex, closeIndex, text));
break;
}
}
}
for (int i = 1; i < text.Length; i++)
{
if (text[i] == '-' && (text[i]-1=='*' || text[i] - 1 == '/'))
{
for (int j=i-1; j>=0; j++)
{
if (text[j] == '+')
{
StringBuilder text1 = new StringBuilder(text);
text1[j] = '-';
text = text1.ToString();
text = text.Remove(i, 1);
break;
}
else if (text[j] == '-')
{
StringBuilder text1 = new StringBuilder(text);
text1[j] = '+';
text = text1.ToString();
text = text.Remove(i, 1);
break;
}
}
}
}
if (text[0] == '-') //für Fehler wenn - als erste Ziffer
{
text = '0' + text;
}
return Calculate(text);
}
public string ResolveBrackets(int openIndex, int closeIndex, string text)
{
string bracketAnswer = Calculate(text.Substring(openIndex +1, closeIndex -1));
return bracketAnswer;
}
}
}
Because you probably add the minus character twice
if (i != text.Length - 1)
{
textList.Add("-");
}
textList.Add("-");
Then, when you loop in step of 2
for (int i = 2; i < textList.Count; i += 2)
You don't have [number] [sign] [number] [sign] anymore.
I suggest you look and the items in your list to see the problem. I would also suggest that you split your logic into smaller methods that could individually be tested.
i think the problem is your use of
double total = Convert.ToDouble(textList[0]);
in DivideAndMultiply
First of all it's best practice to test if the string is null or empty using String.IsNullOrEmpty(textList[0]); and use Double.TryParse instead of convert.
My lab is about schedule and I use modified Kron algorithm.
When the button presses the form should print information on 4 richBoxes.
Sometimes everything is OK but sometimes the form freezes and don't answer. If I open the Task Manager window I see that my app takes about 30% CPU. Maybe it's because of cycle in the button? Maybe I should do more buttons? Or what? I don't understand..
So what's the prob?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;
namespace LW3_OTPR_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBoxZ.Text = "3";
textBoxTasks.Text = "12";
textBoxProcs.Text = "4";
textBoxFrom.Text = "10";
textBoxTo.Text = "20";
}
private void buttonGetResult_Click(object sender, EventArgs e)
{
richTextBoxMatrix.Clear();
richTextBox1.Clear();
richTextBox2.Clear();
richTextBox3.Clear();
int z = Convert.ToInt32(textBoxZ.Text);
for (int i = 0; i < z; i++)
{
richTextBox1.Text += "========= Z = " + (i+1) +" ===========";
richTextBox1.Text += Environment.NewLine;
richTextBox2.Text += "========= Z = " + (i + 1) + " ===========";
richTextBox2.Text += Environment.NewLine;
richTextBox3.Text += "========= Z = " + (i + 1) + " ===========";
richTextBox3.Text += Environment.NewLine;
Work.start1(Convert.ToInt32(textBoxTasks.Text), Convert.ToInt32(textBoxProcs.Text),
Convert.ToInt32(textBoxFrom.Text), Convert.ToInt32(textBoxTo.Text));
richTextBoxMatrix.Text += "Матрица " + (i+1);
richTextBoxMatrix.Text += Environment.NewLine;
richTextBoxMatrix.Text += Work.strWork;
var processors = new Individ(Convert.ToInt32(textBoxTasks.Text),
Convert.ToInt32(textBoxFrom.Text),
Convert.ToInt32(textBoxTo.Text),
Convert.ToInt32(textBoxProcs.Text));
var procMonolit = new IndividMonolit(Convert.ToInt32(textBoxTasks.Text),
Convert.ToInt32(textBoxFrom.Text),
Convert.ToInt32(textBoxTo.Text),
Convert.ToInt32(textBoxProcs.Text));
var procKritWay = new IndividKritWay(Convert.ToInt32(textBoxTasks.Text),
Convert.ToInt32(textBoxFrom.Text),
Convert.ToInt32(textBoxTo.Text),
Convert.ToInt32(textBoxProcs.Text));
richTextBox1.Text += processors.print();
richTextBox2.Text += procKritWay.printKritWay();
richTextBox3.Text += procMonolit.printMonolit();
processors.proc.balance();
procKritWay.procKritWay.balanceKritWay();
procMonolit.procMonolit.balanceMonolit();
richTextBox1.Text += processors.proc.inf;
richTextBox2.Text += procKritWay.procKritWay.infKritWay;
richTextBox3.Text += procMonolit.procMonolit.infMonolit;
}
}
}
static class Work
{
public static string strWork;
static public List<List<int>> arrayTask2d { set; get; }
static public List<int> arrayTask { set; get; }
static public void start1(int countWork, int countProc, int t1, int t2)
{
strWork = string.Empty;
int temp = 0;
arrayTask = new List<int>();
arrayTask2d = new List<List<int>>();
List<int> taskRow = new List<int>();
for (int i = 0; i < countWork; i++)
{
temp = Constant.rnd.Next(t2 - t1) + t1 + 1;
arrayTask.Add(temp);
taskRow = new List<int>();
for (int j = 0; j < countProc; j++)
{
taskRow.Add(temp);
}
arrayTask2d.Add(taskRow);
}
for (int i = 0; i < countWork; i++)
{
for (int j = 0; j < countProc; j++)
{
strWork += arrayTask2d[i][j].ToString() + " ";
}
strWork += Environment.NewLine;
}
}
}
class Proc
{
public string inf;
public string infMonolit;
public string infKritWay;
private List<List<int>> procs;
public List<int> this[int i]
{
get
{
return procs[i];
}
set
{
procs[i] = value;
}
}
public int CountProc
{
get { return procs.Count; }
}
public int delta
{
get
{
return procs.Max((a) => { return a.Sum(); }) - procs.Min((a) => { return a.Sum(); });
}
}
public Proc(int countProc)
{
inf = string.Empty;
infMonolit = string.Empty;
infKritWay = string.Empty;
procs = new List<List<int>>();
for (int i = 0; i < countProc; i++)
procs.Add(new List<int>());
}
private int getIndexOfMax()
{
int result = 0;
for (int i = 0; i < procs.Count; i++)
{
if (procs[i].Sum() > procs[result].Sum())
result = i;
}
return result;
}
public int getIndexOfMin()
{
int result = 0;
for (int i = 0; i < procs.Count; i++)
{
if (procs[i].Sum() < procs[result].Sum())
result = i;
}
return result;
}
private void addInf()
{
for (int i = 0; i < procs.Count; i++)
{
inf += " Процессор " + (i + 1).ToString()+ ": ";
for (int j = 0; j < procs[i].Count; j++)
inf += procs[i][j] + " ";
inf += "|| sum = " + procs[i].Sum();
inf += Environment.NewLine;
}
inf += "Δ = " + delta + Environment.NewLine;
}
private void addInfMonolit()
{
for (int i = 0; i < procs.Count; i++)
{
infMonolit += " Процессор " + (i + 1).ToString() + ": ";
for (int j = 0; j < procs[i].Count; j++)
infMonolit += procs[i][j] + " ";
infMonolit += "|| sum = " + procs[i].Sum();
infMonolit += Environment.NewLine;
}
infMonolit += "Δ = " + delta + Environment.NewLine;
}
private void addInfKritWay()
{
for (int i = 0; i < procs.Count; i++)
{
infKritWay += " Процессор " + (i + 1).ToString() + ": ";
for (int j = 0; j < procs[i].Count; j++)
infKritWay += procs[i][j] + " ";
infKritWay += "|| sum = " + procs[i].Sum();
infKritWay += Environment.NewLine;
}
infKritWay += "Δ = " + delta + Environment.NewLine;
}
public void balance()
{
bool flag = true;
int max = 0;
int min = 0;
int dlt = 0;
while (flag != false)
{
max = getIndexOfMax();
min = getIndexOfMin();
for (int i = 0; i < procs[max].Count; i++)
{
dlt = procs[max].Sum() - procs[min].Sum();
if (procs[max][i] < dlt)
{
procs[min].Add(procs[max][i]);
procs[max].RemoveAt(i);
addInf();
balance();
}
}
for (int i = 0; i < procs[max].Count; i++)
{
for (int j = 0; j < procs[min].Count; j++)
{
if (procs[max][i] > procs[min][j] && procs[max][i] - procs[min][j] < delta)
{
//меняем местами
int temp = procs[max][i];
procs[max][i] = procs[min][j];
procs[min][j] = temp;
addInf();
balance();
}
}
}
flag = false;
}
}
public void balanceKritWay()
{
bool flag = true;
int max = 0;
int min = 0;
int dlt = 0;
while (flag != false)
{
max = getIndexOfMax();
min = getIndexOfMin();
for (int i = 0; i < procs[max].Count; i++)
{
dlt = procs[max].Sum() - procs[min].Sum();
if (procs[max][i] < dlt)
{
procs[min].Add(procs[max][i]);
procs[max].RemoveAt(i);
addInfKritWay();
balanceKritWay();
}
}
for (int i = 0; i < procs[max].Count; i++)
{
for (int j = 0; j < procs[min].Count; j++)
{
if (procs[max][i] > procs[min][j] && procs[max][i] - procs[min][j] < delta)
{
//меняем местами
int temp = procs[max][i];
procs[max][i] = procs[min][j];
procs[min][j] = temp;
addInfKritWay();
balanceKritWay();
}
}
}
flag = false;
}
}
public void balanceMonolit()
{
bool flag = true;
int max = 0;
int min = 0;
int dlt = 0;
while (flag != false)
{
max = getIndexOfMax();
min = getIndexOfMin();
for (int i = 0; i < procs[max].Count; i++)
{
dlt = procs[max].Sum() - procs[min].Sum();
if (procs[max][i] < dlt)
{
procs[min].Add(procs[max][i]);
procs[max].RemoveAt(i);
addInfMonolit();
balanceMonolit();
}
}
for (int i = 0; i < procs[max].Count; i++)
{
for (int j = 0; j < procs[min].Count; j++)
{
if (procs[max][i] > procs[min][j] && procs[max][i] - procs[min][j] < delta)
{
//меняем местами
int temp = procs[max][i];
procs[max][i] = procs[min][j];
procs[min][j] = temp;
addInfMonolit();
balanceMonolit();
}
}
}
flag = false;
}
}
}
class Individ
{
int numbJobs;
int numbProc;
private static uint CountIndivids { get; set; }
//массив для создания расписания
//(массив рандомных чисел каждое из которых соответствует заданию)
public List<int> arrayRandom { set; get; }
public List<int> arrayTasks { set; get; }
public List<int> arrayProc;
public Proc proc;
//public Proc procKritWay;
//максимальный порог рандома
int randLimit;
int x, y;
string inf;
public int Max
{
get
{
return arrayProc.Max();
}
}
public int NumberOfJobs
{
get
{
return arrayTasks.Count;
}
}
public int NumberOfProc
{
get
{
return proc.CountProc;
}
}
public int RandomLimit
{
get
{
return randLimit;
}
}
public Individ() { }
public Individ(Individ copy)
{
arrayRandom = new List<int>(copy.arrayRandom);
arrayTasks = new List<int>(copy.arrayTasks);
//arrayProc = new List<int>(copy.arrayProc);
numbJobs = copy.numbJobs;
numbProc = copy.numbProc;
randLimit = copy.randLimit;
x = copy.x;
y = copy.y;
inf = copy.inf;
}
public Individ(int numberOfJobs, int X, int Y, int numberOfProc, int randomLimit = 255)
{
numbJobs = numberOfJobs; numbProc = numberOfProc; randLimit = randomLimit; x = X; y = Y;
arrayTasks = new List<int>(Work.arrayTask);
arrayRandom = new List<int>();
//заполнили массив рандомных чисел и работы
for (int i = 0; i < numbJobs; i++)
arrayRandom.Add(Constant.rnd.Next(0, randLimit));
proc = new Proc(numbProc);
schedule();
}
private void addInf()
{
inf = "Случайный разброс на процессоры: ";
inf += Environment.NewLine;
for (int i = 0; i < numbProc; i++)
{
inf += " Процессор " + (i + 1).ToString() + ":";
for (int j = 0; j < proc[i].Count; j++)
inf += proc[i][j] + " ";
inf += "|| sum = " + proc[i].Sum();
inf += Environment.NewLine;
}
inf += "Δ = " + proc.delta + Environment.NewLine;
}
//построить расписание
void schedule()
{
inf = string.Empty;
int k = 0;
for (int i = 0; i < proc.CountProc; i++)
proc[i].Clear();
for (int i = 0; i < NumberOfJobs; i++)
{
k = Range.rangeToIndexProc(arrayRandom[i], proc.CountProc, randLimit);
proc[k].Add(arrayTasks[i]);
}
addInf();
}
public string getRandomInString()
{
string result = string.Empty;
foreach (var iter in arrayRandom)
result += iter.ToString() + ' ';
return result;
}
public string print()
{
addInf();
return inf;
}
private int getIndexMin(List<int> list)
{
int result = 0;
for (int i = 0; i < list.Count; i++)
if (list[i] < list[result])
result = i;
return result;
}
public delegate bool sort(int x, int y);
private void sortProc()
{
arrayProc.Sort((a, b) => { return a - b; });
}
}
I'm a math student with little to no experience programming, but I wrote this to act like a brute force algorithm. It seems to run fine except that it runs all the password combinations out to 3 characters for passwords as short as 2. Also I'm sure there's a way to refactor the for and if statements as well. Any help would be appreciated, thanks.
I've already been testing to see if some of the if statements aren't executing, and it looks like the statements with "console.writeln(Is this executing)" aren't executing but I'm not really sure.
public Form1()
{
InitializeComponent();
}
static char[] Match ={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j' ,'k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','C','L','M','N','O','P',
'Q','R','S','T','U','V','X','Y','Z','!','?',' ','*','-','+'};
private string[] tempPass;
private void button1_Click(object sender, EventArgs e)
{
string tempPass1 = "lm";
string result = String.Empty;
int passLength = 1;
int maxLength = 17;
tempPass = new string[passLength];
for (int i = 0; i < Match.Length; i++)
{
if (tempPass1 != result)
{
tempPass[0] = Match[i].ToString();
result = String.Concat(tempPass);
if (passLength > 1)
{
for (int j = 0; j < Match.Length; j++)
{
if (tempPass1 != result)
{
tempPass[1] = Match[j].ToString();
result = String.Concat(tempPass);
if (passLength > 2)
{
for (int k = 0; k < Match.Length; k++)
{
if (tempPass1 != result)
{
tempPass[2] = Match[k].ToString();
result = String.Concat(tempPass);
if (tempPass[0] == "+" && tempPass[1] == "+" && tempPass[2] == "+" && tempPass1 != result)
{
Console.WriteLine("This will execute?");
passLength++;
tempPass = new string[passLength];
k = 0;
j = 0;
i = 0;
}
else if (result == tempPass1)
{
Console.WriteLine("Broken");
Console.WriteLine("This is big gay: " + result);
break;
}
}
}
}
if (tempPass[0] == "+" && tempPass[1] == "+" && tempPass1 != result)
{
Console.WriteLine("Did this execute?");
passLength++;
tempPass = new string[passLength];
j = 0;
i = 0;
}
else if (result == tempPass1)
{
Console.WriteLine("Broken");
Console.WriteLine("This is bigger gay: " + result);
break;
}
}
}
}
//tempPass[1] = "World!";
//Console.WriteLine(result);
if (tempPass[tempPass.Length - 1] == "+" && tempPass1 != result)
{
passLength++;
tempPass = new string[passLength];
Console.WriteLine(tempPass.Length + " " + result + " " + "Success");
Console.WriteLine(i);
i = 0; /**update
j = 0;
k = 0;
l = 0;
m = 0;*/
}
else if (result == tempPass1)
{
Console.WriteLine("Broken");
Console.WriteLine("This is biggest gay: " + result);
}
}
}
}
Play with this; modified from my answer here. It'll show you all the 2 and 3 length combinations. Clicking the button will start/stop the generation process. You need a button, label, and a timer:
public partial class Form1 : Form
{
private Revision rev;
public Form1()
{
InitializeComponent();
rev = new Revision("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!? *-+", "00");
label1.Text = rev.CurrentRevision;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
}
private void timer1_Tick(object sender, EventArgs e)
{
rev.NextRevision();
if (rev.CurrentRevision.Length == 4)
{
timer1.Stop();
MessageBox.Show("Sequence Complete");
// make it start back at the beginning?
rev = new Revision("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!? *-+", "00");
label1.Text = rev.CurrentRevision;
}
else
{
label1.Text = rev.CurrentRevision;
}
}
}
public class Revision
{
private string chars;
private char[] values;
private System.Text.StringBuilder curRevision;
public Revision()
{
this.DefaultRevision();
}
public Revision(string validChars)
{
if (validChars.Length > 0)
{
chars = validChars;
values = validChars.ToCharArray();
curRevision = new System.Text.StringBuilder(values[0]);
}
else
{
this.DefaultRevision();
}
}
public Revision(string validChars, string startingRevision)
: this(validChars)
{
curRevision = new System.Text.StringBuilder(startingRevision.ToUpper());
int i = 0;
for (i = 0; i <= curRevision.Length - 1; i++)
{
if (Array.IndexOf(values, curRevision[i]) == -1)
{
curRevision = new System.Text.StringBuilder(values[0]);
break;
}
}
}
private void DefaultRevision()
{
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
values = chars.ToCharArray();
curRevision = new System.Text.StringBuilder(values[0]);
}
public string ValidChars
{
get { return chars; }
}
public string CurrentRevision
{
get { return curRevision.ToString(); }
}
public string NextRevision(int numRevisions = 1)
{
bool forward = (numRevisions > 0);
numRevisions = Math.Abs(numRevisions);
int i = 0;
for (i = 1; i <= numRevisions; i++)
{
if (forward)
{
this.Increment();
}
else
{
this.Decrement();
}
}
return this.CurrentRevision;
}
private void Increment()
{
char curChar = curRevision[curRevision.Length - 1];
int index = Array.IndexOf(values, curChar);
if (index < (chars.Length - 1))
{
index = index + 1;
curRevision[curRevision.Length - 1] = values[index];
}
else
{
curRevision[curRevision.Length - 1] = values[0];
int i = 0;
int startPosition = curRevision.Length - 2;
for (i = startPosition; i >= 0; i += -1)
{
curChar = curRevision[i];
index = Array.IndexOf(values, curChar);
if (index < (values.Length - 1))
{
index = index + 1;
curRevision[i] = values[index];
return;
}
else
{
curRevision[i] = values[0];
}
}
curRevision.Insert(0, values[0]);
}
}
private void Decrement()
{
char curChar = curRevision[curRevision.Length - 1];
int index = Array.IndexOf(values, curChar);
if (index > 0)
{
index = index - 1;
curRevision[curRevision.Length - 1] = values[index];
}
else
{
curRevision[curRevision.Length - 1] = values[values.Length - 1];
int i = 0;
int startPosition = curRevision.Length - 2;
for (i = startPosition; i >= 0; i += -1)
{
curChar = curRevision[i];
index = Array.IndexOf(values, curChar);
if (index > 0)
{
index = index - 1;
curRevision[i] = values[index];
return;
}
else
{
curRevision[i] = values[values.Length - 1];
}
}
curRevision.Remove(0, 1);
if (curRevision.Length == 0)
{
curRevision.Insert(0, values[0]);
}
}
}
}
I'm trying to create a basic weather app where you can enter readings for a city and it will display the average, lowest temperature and highest temperature.
I created a 2d array (intTemps) with 5 rows (citys) and 4 columns (4 readings). Whenever I add a temperature to the listbox, it always displays in the upper left. When I add another temperature, it displays the same temperature that was just displayed and the current temperature.
The code is based on an example my professor wrote, so I'm not sure why its not displaying right.
public partial class Form1 : Form
{
string[] strNames = { "Livonia",
"Redford" ,
"Novi" ,
"Westland",
"Northville" };
int[,] intTemps = new int[5, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i <= 4; i++)
{
cobNames.Items.Add(strNames[i]);
lstNames.Items.Add(strNames[i]);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (cobNames.SelectedIndex >= 0 && cobNames.SelectedIndex <= 4)
{
if (intTemps[cobNames.SelectedIndex, (int)nudTemp.Value - 1] == 0)
{
intTemps[cobNames.SelectedIndex, (int)nudTemp.Value - 1] = Int32.Parse(txtTemp.Text);
}
else
{
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show("Do you want to change temps?", "Temps already exist!", buttons);
if (result == System.Windows.Forms.DialogResult.Yes)
{
intTemps[cobNames.SelectedIndex, (int)nudTemp.Value - 1] = Int32.Parse(txtTemp.Text);
}
}
displayTemps();
}
else
{
MessageBox.Show("You must select a valid name!");
}
}
catch (FormatException)
{
MessageBox.Show("Temps must be integers");
}
}
private void displayTemps()
{
string strLine;
lstTemp.Items.Clear();
double[] dblAverages = new double[5];
int intNonBlank = 0;
for (int l = 0; l <= 4; l++)
{
intNonBlank = 0;
for (int c = 0; c <= 3; c++)
{
if (intTemps[l, c] != 0)
{
dblAverages[l] += intTemps[l, c];
intNonBlank++;
}
}
if (intNonBlank != 0)
{
dblAverages[l] /= intNonBlank;
}
}
for (int l = 0; l <= 4; l++)
{
strLine = " ";
for (int c = 0; c <= 3; c++)
{
if (intTemps[l, c] == 0)
{
strLine += " ";
}
else
{
if (intTemps[l, c] == 120)
{
strLine += intTemps[l, c] + " ";
}
else
{
strLine += intTemps[l, c] + " ";
}
lstTemp.Items.Add(strLine);
}
}
}
}
}
I rewrite your displayTemps() procedure. This wil add to lstTemp all information you need:
private void displayTemps()
{
string strLine;
lstTemp.Items.Clear();
double[] dblAverages = new double[5];
int intNonBlank = 0;
for (int l = 0; l <= 4; l++)
{
intNonBlank = 0;
for (int c = 0; c <= 3; c++)
{
if (intTemps[l, c] != 0)
{
dblAverages[l] += intTemps[l, c];
intNonBlank++;
}
}
if (intNonBlank != 0)
{
dblAverages[l] /= intNonBlank;
}
int min_temp = System.Linq.Enumerable.Range(0, 4).
Select(i => intTemps[l, i]).Min();
int max_temp = System.Linq.Enumerable.Range(0, 4).
Select(i => intTemps[l, i]).Max();
lstTemp.Items.Add(
"Average temp for city "+ l +": " + dblAverages[l] + " " +
"Minimum " + min_temp + " " +
"Maximum " + max_temp);
}
}
I have come up with this code, it works for what the teacher wants. Counts spaces, counts words, does a substring search and individually counts letters and shows you what letters are used.
But I need to convert it into an array method rather than a 600 line do while loop. I really have no clue how to do this. Could anyone give me input?
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int m = 0;
int n = 0;
int o = 0;
int p = 0;
int q = 0;
int r = 0;
int s = 0;
int t = 0;
int u = 0;
int v = 0;
int w = 0;
int x = 0;
int y = 0;
int z = 0;
int A = 0;
int B = 0;
int C = 0;
int D = 0;
int E = 0;
int F = 0;
int G = 0;
int H = 0;
int I = 0;
int J = 0;
int K = 0;
int L = 0;
int M = 0;
int N = 0;
int O = 0;
int P = 0;
int Q = 0;
int R = 0;
int S = 0;
int T = 0;
int U = 0;
int V = 0;
int W = 0;
int X = 0;
int Y = 0;
int Z = 0;
int readChar = 0;
int word = 0;
int lower = 0;
int upper = 0;
string inputString ="";
char ch = ' ';
string findString = "";
int space = 0;
int startingPoint = 0;
int findStringCount = 0;
Console.Write("Please enter a string: ");
do{
readChar = Console.Read();
ch = Convert.ToChar(readChar);
if (ch.Equals(' '))
{
space++;
}
else if (Char.IsLower(ch))
{
lower++;
if (ch.Equals('a'))
{
a++;
}
else if (ch.Equals('b'))
{
b++;
}
else if (ch.Equals('c'))
{
c++;
}
else if (ch.Equals('d'))
{
d++;
}
else if (ch.Equals('e'))
{
e++;
}
else if (ch.Equals('f'))
{
f++;
}
else if (ch.Equals('g'))
{
g++;
}
else if (ch.Equals('h'))
{
h++;
}
else if (ch.Equals('i'))
{
i++;
}
else if (ch.Equals('j'))
{
j++;
}
else if (ch.Equals('k'))
{
k++;
}
else if (ch.Equals('l'))
{
l++;
}
else if (ch.Equals('m'))
{
m++;
}
else if (ch.Equals('n'))
{
n++;
}
else if (ch.Equals('o'))
{
o++;
}
else if (ch.Equals('p'))
{
p++;
}
else if (ch.Equals('q'))
{
q++;
}
else if (ch.Equals('r'))
{
r++;
}
else if (ch.Equals('s'))
{
s++;
}
else if (ch.Equals('t'))
{
t++;
}
else if (ch.Equals('u'))
{
u++;
}
else if (ch.Equals('v'))
{
v++;
}
else if (ch.Equals('w'))
{
w++;
}
else if (ch.Equals('x'))
{
x++;
}
else if (ch.Equals('y'))
{
y++;
}
else if (ch.Equals('z'))
{
z++;
}
}
else if (Char.IsUpper(ch))
{
upper++;
if (ch.Equals('A'))
{
A++;
}
else if (ch.Equals('B'))
{
B++;
}
else if (ch.Equals('C'))
{
C++;
}
else if (ch.Equals('D'))
{
D++;
}
else if (ch.Equals('E'))
{
E++;
}
else if (ch.Equals('F'))
{
F++;
}
else if (ch.Equals('G'))
{
G++;
}
else if (ch.Equals('H'))
{
H++;
}
else if (ch.Equals('I'))
{
I++;
}
else if (ch.Equals('J'))
{
J++;
}
else if (ch.Equals('K'))
{
K++;
}
else if (ch.Equals('L'))
{
L++;
}
else if (ch.Equals('M'))
{
M++;
}
else if (ch.Equals('N'))
{
N++;
}
else if (ch.Equals('O'))
{
O++;
}
else if (ch.Equals('P'))
{
P++;
}
else if (ch.Equals('Q'))
{
Q++;
}
else if (ch.Equals('R'))
{
R++;
}
else if (ch.Equals('S'))
{
S++;
}
else if (ch.Equals('T'))
{
T++;
}
else if (ch.Equals('U'))
{
U++;
}
else if (ch.Equals('V'))
{
V++;
}
else if (ch.Equals('W'))
{
W++;
}
else if (ch.Equals('X'))
{
X++;
}
else if (ch.Equals('Y'))
{
Y++;
}
else if (ch.Equals('Z'))
{
Z++;
}
}
if (((ch.Equals(' ') && (!inputString.EndsWith(" ")))||(ch.Equals('\r') && (!inputString.EndsWith(" "))))&&(inputString!=""))
{
word++;
}
inputString = inputString + ch;
} while (ch != '\r');
Console.ReadLine();
Console.WriteLine("Report on {0}",inputString);
Console.WriteLine("# of spaces {0}",space);
Console.WriteLine("# of lower {0}", lower);
Console.WriteLine("# of upper {0}", upper);
Console.WriteLine("# of word {0}", word);
Console.WriteLine("UPPERCASE");
if (A >= 1)
{
Console.WriteLine("A = {0}",A);
}
if (B >= 1)
{
Console.WriteLine("B = {0}",B);
}
if (C >= 1)
{
Console.WriteLine("C = {0}", C);
}
if (D >= 1)
{
Console.WriteLine("D = {0}", D);
}
if (E >= 1)
{
Console.WriteLine("E = {0}", E);
}
if (F >= 1)
{
Console.WriteLine("F = {0}", F);
} if (G >= 1)
{
Console.WriteLine("G = {0}", G);
}
if (H >= 1)
{
Console.WriteLine("H = {0}", H);
}
if (I >= 1)
{
Console.WriteLine("I = {0}", I);
}
if (J >= 1)
{
Console.WriteLine("J = {0}", J);
}
if (K >= 1)
{
Console.WriteLine("K = {0}", K);
}
if (L >= 1)
{
Console.WriteLine("L = {0}", L);
}
if (M >= 1)
{
Console.WriteLine("M = {0}", M);
}
if (N >= 1)
{
Console.WriteLine("N = {0}",N);
}
if (O >= 1)
{
Console.WriteLine("O = {0}",O);
}
if (P >= 1)
{
Console.WriteLine("P = {0}",P);
}
if (Q >= 1)
{
Console.WriteLine("Q = {0}",Q);
}
if (R >= 1)
{
Console.WriteLine("R = {0}",R);
}
if (S >= 1)
{
Console.WriteLine("S = {0}",S);
}
if (T >= 1)
{
Console.WriteLine("T = {0}",T);
}
if (U >= 1)
{
Console.WriteLine("U = {0}",U);
}
if (V >= 1)
{
Console.WriteLine("V = {0}",V);
}
if (W >= 1)
{
Console.WriteLine("W = {0}",W);
}
if (X >= 1)
{
Console.WriteLine("X = {0}",X);
}
if (Y >= 1)
{
Console.WriteLine("Y = {0}",Y);
}
if (Z >= 1)
{
Console.WriteLine("Z = {0}",Z);
}
Console.WriteLine("LOWERCASE");
if (a >= 1)
{
Console.WriteLine("a = {0}", a);
}
if (b >= 1)
{
Console.WriteLine("b = {0}", b);
}
if (c >= 1)
{
Console.WriteLine("c = {0}", c);
}
if (d >= 1)
{
Console.WriteLine("d = {0}", d);
}
if (e >= 1)
{
Console.WriteLine("e = {0}", e);
}
if (f >= 1)
{
Console.WriteLine("f = {0}", f);
} if (g >= 1)
{
Console.WriteLine("g = {0}", g);
}
if (h >= 1)
{
Console.WriteLine("h = {0}", h);
}
if (i >= 1)
{
Console.WriteLine("i = {0}", i);
}
if (j >= 1)
{
Console.WriteLine("j = {0}", j);
}
if (k >= 1)
{
Console.WriteLine("k = {0}", k);
}
if (l >= 1)
{
Console.WriteLine("l = {0}", l);
}
if (m >= 1)
{
Console.WriteLine("m = {0}", m);
}
if (n >= 1)
{
Console.WriteLine("n = {0}", n);
}
if (o >= 1)
{
Console.WriteLine("o = {0}", o);
}
if (p >= 1)
{
Console.WriteLine("p = {0}", p);
}
if (q >= 1)
{
Console.WriteLine("q = {0}", q);
}
if (r >= 1)
{
Console.WriteLine("r = {0}", r);
}
if (s >= 1)
{
Console.WriteLine("s = {0}", s);
}
if (t >= 1)
{
Console.WriteLine("t = {0}", t);
}
if (u >= 1)
{
Console.WriteLine("u = {0}", u);
}
if (v >= 1)
{
Console.WriteLine("v = {0}", v);
}
if (w >= 1)
{
Console.WriteLine("w = {0}", w);
}
if (x >= 1)
{
Console.WriteLine("x = {0}", x);
}
if (y >= 1)
{
Console.WriteLine("y = {0}", y);
}
if (z >= 1)
{
Console.WriteLine("z = {0}", z);
}
Console.WriteLine();
Console.Write("Please enter a substring ");
findString = Console.ReadLine();
if (findString.Length <= inputString.Length)
{
do
{
if (inputString.IndexOf(findString, startingPoint) != -1)
{
findStringCount++;
startingPoint = inputString.IndexOf(findString, startingPoint) + findString.Length;
}
} while (inputString.IndexOf(findString, startingPoint) != -1);
}
else
{
Console.WriteLine("Substring is too long!");
}
Console.WriteLine("The number of times that {0} is found in the text is {1}", findString, findStringCount);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] counterArray = new int[123];
string myString;
int wordCounted = 0;
int result = 0;
//Prompt user and get value
Console.Write("Please enter a string: ");
myString =
Console.ReadLine();
//Word count
for (int i = 1; i < myString.Length; i++)
{
if (char.IsWhiteSpace(myString[i - 1]))
{
if (char.IsLetterOrDigit(myString[i]) ||
char.IsPunctuation(myString[i]))
{
wordCounted++;
}
}
}
if (myString.Length > 2)
{
wordCounted++;
}
//White space count
foreach (char countSpace in myString)
{
if (char.IsWhiteSpace(countSpace))
{
result++;
}
}
//Display words and space count,
Console.WriteLine("\nWORDS:\t\t{0}", wordCounted);
Console.WriteLine("SPACES: \t{0}", result);
for (int x = 0; x < myString.Length; x++)
{
int myValue = Convert.ToInt32(myString[x]);
counterArray[myValue]++;
}
//Display uppercase letter count
Console.WriteLine("\nUPPERCASE LETTERS: ");
//Counting uppercase letter
for (int y = 65; y < 91; y++)
{
if (counterArray[y] > 0)
{
Console.WriteLine("\t\t{0}: \t{1}", Convert.ToChar(y), counterArray[y]);
}
}
//Display lowercase letter count
Console.WriteLine("LOWERCASE LETTERS: ");
//Counting lowercase letter
for (int z = 97; z < 123; z++)
{
if (counterArray[z] > 0)
{
Console.WriteLine("\t\t{0}: \t{1}", Convert.ToChar(z), counterArray[z]);
}
}
int startingPoint = 0;
int findStringCount = 0;
Console.Write("Please enter a substring ");
findString = Console.ReadLine();
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
}
}
}
Here is a way to use the dictionary and Linq. (Edit added the uppercase linq operation to fill in the A-Z to compliment the a-z):
Dictionary<char, int> myLetters = new Dictionary<char, int>();
Enumerable.Range(0,26)
.Select( indx => (char)+('a' + indx))
.Union( Enumerable.Range(0,26)
.Select( indx => (char)+('A' + indx)))
.ToList()
.ForEach( chr => myLetters.Add( chr, 0));
myLetters['a'] = 2;
myLetters['Z'] = 3;
myLetters.ToList()
.ForEach( ml => Console.WriteLine("{0} : {1}", ml.Key, ml.Value));
/* Prints out
a : 2
b : 0
c : 0
...
Z : 3
*/
Note the above is for learning purposes, I would actually do the myLetters assignment with the enumerable in one fell swoop such as:
Dictionary<char, int> myLetters =
Enumerable.Range(0,26)
.Select( indx => (char)+('a' + indx))
.Union( Enumerable.Range(0,26)
.Select( indx => (char)+('A' + indx)))
.ToDictionary (letter => letter, letter => 0);
The ideal solution would be to use a Dictionary<char,int>, but if the homework specifically requires an array, you can use the fact that the ASCII representation of alphabetic characters are serial. That is, A=65, B=66,...,Z=90 and a=97, b=98,...,z=122. For example:
var uppercase = new int[26];
var lowercase = new int[26];
if( ch >= 'A' && ch <= 'Z' )
uppercase[ch-'A']++;
if( ch >= 'a' && ch <= 'z' )
lowercase[ch-'a']++;
Then when you go print it out, you can just cast the indeces to type char:
for( var i='A'; i<='Z'; i++ ) {
Console.WriteLine( (char)i + " = " + uppercase[i-'A'] );
}
I'll leave the rest of the implementation up to you.
Well IMHO the easiest way to get an array of characters would be this:
char[] alphaLower = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
char[] alphaUpper = //same thing as above with uppercase letters;
at this point you can do your calculations inside of a loop. Something like this:
foreach(char c in alphaLower)
{
//possibly a nested foreach here to process each character of input against each char in the alphabet?
//write your calculation to console
}
I wouldn't be surprised to see what you have above rewritten in as little as 20 lines of code. Post what you come up with in your next iteration and we will continue to point you in the right direction.
Try using a hashtable...where they key is the letter, and the value is the number of times it occurs
if (ht.Contains({yourletter}))
//increment the value by 1
if (ht.ContainsKey(letter))
ht[letter] = Convert.ToInt32(ht[letter]) + 1;
else
ht.Add(letter, 1);
ASCII space is continuous for capital letters, and for small caps, capital A starts from decimal 65.
see http://www.asciitable.com/ for details
you should allocate an array for all characters in lower part of ascii table (127)
var countingchars = new int[128];
then you loop over chars in string and do sth like in this loop:
countingchars[(byte)currentchar]++;
whenever you encounter (byte)currentchar == 32, you should increment word count
when you have gone through entire string,
get spaces from countingchars[32]
get caps from 65 - 90
get small letters from 97-122
hope this is enough.
I am leaving it up to you for putting it nicely into c#
Hope this will help in learning
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace HomeWork
{
class Alphabets
{
static void Main(string[] args)
{
string sentence = null;
string findString = null;
int numericCount;
int upperCount;
int lowerCount;
int specialCount;
int countBlankSpace;
int countWord;
Console.Write("Please enter a string: ");
sentence = Console.ReadLine();
numericCount = Regex.Matches(sentence, #"\d").Count;
upperCount = Regex.Matches(sentence, #"[A-Z]").Count;
lowerCount = Regex.Matches(sentence, #"[a-z]").Count;
specialCount = Regex.Matches(sentence, #"[!""£$%^&*())]").Count;
countBlankSpace = new Regex(" ").Matches(sentence).Count;
countWord = Regex.Matches(sentence, #"[\S]+").Count;
Console.WriteLine("Report on {0}",sentence);
Console.WriteLine("# of spaces {0}", countBlankSpace);
Console.WriteLine("# of lower {0}", lowerCount);
Console.WriteLine("# of upper {0}", upperCount);
Console.WriteLine("# of word {0}", countWord);
Console.WriteLine("# of Special Characters {0}", specialCount);
Console.Write("Please enter a substring:");
findString = Console.ReadLine();
Alphabets.findSubString(findString, sentence);
Console.WriteLine("\nLowercase Letters \n");
Alphabets.lowerLetters(sentence);
Console.WriteLine("\nUppercase Letters \n");
Alphabets.upperLetters(sentence);
Console.ReadLine();
}
public static void lowerLetters(string sentence)
{
int[] upper = new int[(int)char.MaxValue];
// 1.
// Iterate over each character.
foreach (char t in sentence)
{
// Increment table.
upper[(int)t]++;
}
// 2.
// Write all letters found.
for (int i = 0; i < (int)char.MaxValue; i++)
{
if (upper[i] > 0 &&
char.IsLower((char)i))
{
Console.WriteLine("Letter: {0} = {1}",
(char)i,
upper[i]);
}
}
}
public static void upperLetters(string sentence)
{
int[] upper = new int[(int)char.MaxValue];
// 1.
// Iterate over each character.
foreach (char t in sentence)
{
// Increment table.
upper[(int)t]++;
}
// 2.
// Write all letters found.
for (int i = 0; i < (int)char.MaxValue; i++)
{
if (upper[i] > 0 &&
char.IsUpper((char)i))
{
Console.WriteLine("Letter: {0} = {1}",
(char)i,
upper[i]);
}
}
}
public static void findSubString(string findString, string sentence)
{
int findStringCount = 0;
int startingPoint = 0;
if (findString.Length <= sentence.Length)
{
do
{
if (sentence.IndexOf(findString, startingPoint) != -1)
{
findStringCount++;
startingPoint = sentence.IndexOf(findString, startingPoint) + findString.Length;
}
} while (sentence.IndexOf(findString, startingPoint) != -1);
}
else
{
Console.WriteLine("Substring is too long!");
}
Console.WriteLine("The number of times that {0} is found in the text is {1}", findString, findStringCount);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] counterArray = new int[123];
string myString;
int wordCounted = 0;
int result = 0;
//Prompt user and get value
myString = getStringMethod();
//Word count
wordCounted = countWordsMethod(myString, wordCounted);
//White space count
result = spaceCounterMethod(myString, result);
//Display words and space count,
displayCountMethod(counterArray, myString, wordCounted, result);
//Display uppercase letter count
displayUpperMethod();
//Counting uppercase letter
uppserCaseMethod(counterArray);
//Display lowercase letter count
displayLowerMethod();
//Counting lowercase letter
lowerCaseMethod(counterArray);
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
}
private static void displayLowerMethod()
{
Console.WriteLine("LOWERCASE LETTERS: ");
}
private static void displayUpperMethod()
{
Console.WriteLine("\nUPPERCASE LETTERS: ");
}
private static void lowerCaseMethod(int[] counterArray)
{
for (int z = 97; z < 123; z++)
{
if (counterArray[z] > 0)
{
Console.WriteLine("\t\t{0}: \t{1}", Convert.ToChar(z), counterArray[z]);
}
}
}
private static void upp