is there a shortcut method for aligning the text in the first line with the second line in console?
example:
Enter your name: Charles
Enter your student number: 20130140
//and the output should be like this:
Name Student Number
Charles 20130140
Here is my code but it's in a long method.
class MainClass
{
public static void Main (string[] args)
{
int num, nam;
string snum, name, sec;
int num1, num2, num3;
int var;
int bosh;
Console.WriteLine ("Enter student number: ");
snum = Console.ReadLine ();
Console.WriteLine ("Enter Name: ");
name = Console.ReadLine ();
Console.WriteLine ("Enter Section: ");
sec = Console.ReadLine ();
num1 = snum.Length;
num2 = name.Length;
num3 = sec.Length;
Console.WriteLine (" Student Number Name Section ");
Console.Write("\n");
if (num1 <= 14) {
num = (14 - num1) / 2;
var = (14 - num1) - num;
for (int i = 0; i < num; i++) {
Console.Write (" ");
}
Console.Write (" " + snum);
if (num2 <= 4) {
nam = (4 - num2) / 2;
//sum of all sapaces
bosh = var + nam + 8;
for (int i = 0; i < bosh; i++) {
Console.Write (" ");
}
Console.Write (name);
} else {
nam = ( num2 - 4) / 2;
//sum of all sapaces
bosh = var + (8 - nam);
for (int i = 0; i < bosh; i++) {
Console.Write (" ");
}
Console.Write (name);
}
} else if (num1 > 14){
num = 8 - ((num1 - 14) / 2);
for (int i = 0; i < num; i++) {
Console.Write (" ");
}
Console.Write (snum);
if (num2 <= 4) {
nam = (4 - num2) / 2;
//sum of all sapaces
bosh = nam + num;
for (int i = 0; i < bosh; i++) {
Console.Write (" ");
}
Console.Write (name);
} else {
nam = (num2 - 4) / 2;
//sum of all sapaces
bosh = num - nam;
for (int i = 0; i < bosh; i++) {
Console.Write (" ");
}
Console.Write (name);
}
}
Console.ReadKey ();
}
}