Hi everyone , first thank you for reading this, I'm very rookie to develop in C#, and I'm trying to develop an app for university (just for practice), well it's not finished yet, But I have a Problem with the "Padleft", take a look please I need Help. Sorry for the code I'm really very rookie here you are.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace Payment
{
class Program
{
public struct University
{
public string StudentName;
public DateTime InscriptionDate;
public DateTime EndDate;
public decimal Payment;
//public string Signatures;
public int StudentID;
}
public static void Main(string[] args)
{
int TotalData = 5;
int Capacity = 0;
University[] Regedit = new University[TotalData];
string PleaseSelect;
Console.WriteLine("Wellcome to the university!:");
Console.WriteLine();
Console.Write("\nSelect the option:");
Console.WriteLine("\n1-Create a new student:");
Console.WriteLine("2-Search for Student payment");
Console.WriteLine("3-No paid");
PleaseSelect = Console.ReadLine();
switch (PleaseSelect)
{
case "1":
if (Capacity < TotalData)
{
Console.WriteLine("First data:", Capacity + 1);
Console.WriteLine("Write the name of the student please!");
Regedit[Capacity].StudentName = Console.ReadLine();
Console.WriteLine("Student' ID");
Regedit[Capacity].StudentID = Convert.ToInt32(Console.ReadLine());
/*Console.WriteLine("Selection of signatures");
Regedit[Capacity].Signatures = Console.WriteLine();*/
string[] Signatures = new string[5];
string Selections;
int i;
for (i = 0; i<= 4 ; i++)
{
Console.WriteLine("Start your selection:{0}",i+1);
Signatures[i] = Console.ReadLine();
}
Selections = string.Empty;
for (i = 0; i <= 4; i++)
Selections += Signatures[i];
Console.WriteLine("Your selection:{0}",Selections.PadLeft(Signatures[i]));
Console.WriteLine("Payment");
Regedit[Capacity].Payment = Convert.ToDecimal(Console.ReadLine());
if (Regedit[Capacity].Payment != 50) {
Console.WriteLine("No Enough for the quarter");
}
else Console.WriteLine("You payment is good have a good luck!:");
}
break;
default:
break;
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Loading

Javeed M ShaikhPosted Apr 3, 2013, 2:05 PM
Freddy AbreuPosted Apr 3, 2013, 2:18 PM
Freddy AbreuPosted Apr 3, 2013, 1:55 PM
string[] Signatures = new string[5];
string Selections;
int i;
for (i = 0; i<= 4 ; i++)
{
Console.WriteLine("Start your selection:{0}",i+1);
Signatures[i] = Console.ReadLine();
}
Selections = string.Empty;
for (i = 0; i <= 4; i++)
{
Selections += Signatures[i];
Console.WriteLine("Your selection:{0}",Selections);
}
foreach (var X in Signatures) {
Console.WriteLine("",X);
}
But the answer was very fast, I'm really grateful, you know I was afraid to get into this Forum because there are a lot of good developers in here, and I was afraid they make joke of me, but I see this a quite different Forum thanks. To be my first question, I'm good.
Bye.
Javeed M ShaikhPosted Apr 3, 2013, 1:29 PM
Freddy AbreuPosted Apr 3, 2013, 12:51 PM
Best regards.
An exception of type system.indexOutoftheRangeException was thrown :\nindex was outside of the bounds of the array.
By: Freddy
Javeed M ShaikhPosted Apr 3, 2013, 11:57 AM
Taking a look at your code i think you need to pass an int to PadLeft.
your code line:
Console.WriteLine("Your selection:{0}",Selections.PadLeft(Signatures[i]));
replace it with this line:
Console.WriteLine("Your selection:{0}",Selections.PadLeft(Convert.ToInt32(Signatures[i])));