here is my code with the comments. so im having trouble exiting out of the loop. i know it shoud be if(contd = true) or something then it should exit out, but also if they enter Y to keep going, how do i get back into the loop? another thing is how to sort this by abc order. and then how do i do the reverse from Z-A. Thanks for your help, clueless beginner here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string lastName;
string [] lastName = new string[]; //array list of last names
int index;
string contd;
for (index=0;index++)
{
Console.Write("Enter a last name: ");
lastName[index] = Convert.ToString(Console.ReadLine());
Console.Write("Keep going? (Y/N): ");
//prompts user to keep inputting or exit out
contd = Convert.ToString(Console.ReadLine());
if (contd = "n"(Console.ReadLine());
{
//exit out of last name input
}
else contd = "y"(Console.ReadLine());
{
//go back into last name input
}
}
Console.WriteLine((index+1) + " last names entered");
//shows how many last names were entered
Console.WriteLine(); //spacing
//display last names
Console.WriteLine("Names in Acsending Order"); Console.WriteLine();
for(index=0; index++)
//shows the last names in order from A-Z (acsending)
{
Console.WriteLine(lastName[index]);
}
Console.WriteLine();
Console.WriteLine("Names in Descending Order"); Console.WriteLine();
for(index=0; index--)
//shows back last names in reverse order Z-A (descending)
{
Console.WriteLine(lastName[index]); Console.WriteLine();
}
Console.ReadLine();
}
}
}
Aucun commentaire:
Enregistrer un commentaire