By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,912 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Make a program that associates all 26 English alphabets A-Z with the index 1-26. User

P: 1
Make a program that associates all 26 English alphabets A-Z with the index 1-26. User will enter a number from 1 to 26 and it will show the associated alphabet.
4 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,223
well - never used c# but found a online fiddle to fiddle around with c# :) the basic idea could look like something like this:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {    
  7.         char [] alpha = {'a', 'b', 'c', 'd'};
  8.  
  9.         string txt = Console.ReadLine();
  10.  
  11.         Console.WriteLine(
  12.             alpha[Convert.ToInt32(txt)]
  13.         );
  14.     }
  15. }
note that it needs adaption to your real case - and probably correct error handling and so forth. the idea is just to use an array with the elements you want to retrieve. now the input should be an integer between 0 and the array's length which then directly can be used to acces the corresponding element in the array.
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.