In: Computer Science
Please code C#
10.
Sample run:
“Name?”
James
“Height?”
50
“Continue?”
True
“Name?”
Sarah
“Height?”
60
“Continue?”
False
“Sarah is the tallest at 60 inches”
Code is Given Below:
===========================
using System;
using System.Collections;
class HelloWorld {
static void Main() {
//creating array list to hold names and height
ArrayList names=new ArrayList();
ArrayList heights=new ArrayList();
while(true){
//asking user to enter data
Console.WriteLine("Name?");
string name=Console.ReadLine();
Console.WriteLine("Height?");
int height=Convert.ToInt32(Console.ReadLine());
names.Add(name);
heights.Add(height);
Console.WriteLine("Continue?");
string option = Console.ReadLine();
//checking if user want to continue or not
if(string.Equals(option, "True",
StringComparison.OrdinalIgnoreCase))
continue;
else
break;
}
//finding person with maximum height in array list
int index=0;
int maxHeight=(int)heights[0];
for(int i=1;i<names.Count;i++ ){
if((int)heights[i]>maxHeight){
maxHeight=(int)heights[i];
index=i;
}
}
//displaying data
Console.WriteLine(names[index]+" is the tallest at "+maxHeight+"
inches");
}
}
Output:
===============
Code Snapshot:
==============