• 0

Hello everybody, I have a question for while loop on C#


Question

Print the decimal, octal, and hexadecimal values of all characters between the start and stop characters entered by a user. For example, if the user enters an a and a z, the program should print all the characters between a and z and their respective numerical values. Make sure that the second character entered by the user occurs later in the alphabet than the first character. If it does not, write a loop that repeatedly asks the user for a valid second character until one is entered. Your output should be formatted as shown below

Letter           Decimal                Octal      Hex

a                              97           141         61

b                             98           142         62

c                              99           143         63

d                             100         144         64

e                             101         145         65

Thanks...

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1
charletter1, letter2;Console.Write("Enter the first letter: ");letter1 = Convert.ToChar(Console.ReadLine());do{Console.Write("Enter the second letter: ");letter2 = Convert.ToChar(Console.ReadLine());} while(Convert.ToInt32(letter1) > Convert.ToInt32(letter2));intcounter;counter = Convert.ToInt32(letter1);do{intoctal=counter , num=0,remainder=0;do{remainder = remainder +octal % 8* (int)Math.Pow(10, num);
octal = octal / 8;num++;} while(octal/8!=0);remainder = remainder + octal % 8 * (int)Math.Pow(10, num);Console.WriteLine("{0}---{1}---{2}---{3:x}", Convert.ToChar(counter), counter,remainder , counter);counter++;} while(counter <= Convert.ToInt32(letter2));

 

  • Thanks 1
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.