Esempio n. 1
0
		private static void doStandard(){
			Console.WriteLine("Welcome! Let's assign values to a couple of structs" +
				" in the array...");

			// Student 1 inputs
			Student st = new Student();
			st.stName = "Michael Kiske";
			st.stAdress = "C/ Schopenstehl 23, Hamburg, Germany";
			st.stBirthday = new DateTime(1968,1,24);
			students[0] = st;
			// Student 2 inputs
			st = new Student();
			st.stName = "Henrik Klingenberg";
			st.stAdress = "C/ Härnösandinkatu 10, Kokkola, Finland";
			st.stBirthday = new DateTime(1978,10,21);
			students[1] = st;
			//
			Console.WriteLine("Done!");
			Console.WriteLine("Now we're going to show all data...\n");
			// Student's info output
			for(int i = 0; i < 2; i++){
				Console.WriteLine("Student {0} name: {1}", (i + 1), students[i].stName);
				Console.WriteLine("Student {0} adress: {1}", (i + 1), students[i].stAdress);
				Console.WriteLine("Student {0} birthday: {1}/{2}/{3}", (i + 1),
				                  students[i].stBirthday.Day,
				                  students[i].stBirthday.Month,
				                  students[i].stBirthday.Year);
				Console.WriteLine();
			}
		}
Esempio n. 2
0
		private static void doChallenge(){
			Console.WriteLine("Welcome! Let's record our students information. You'll be able" +
			                  " to fill a maximum of 5 gaps.");
			Console.WriteLine();
			for(int i = 0; i < students.Length; i++){
				// First we ask for the student's data
				Console.Write("Student's name: ");
				string name = Console.ReadLine();
				Console.WriteLine();
				Console.Write("Student's adress: ");
				string adress = Console.ReadLine();
				Console.WriteLine();
				Console.Write("Student's birthday (day): ");
				int day = Int32.Parse(Console.ReadLine());
				Console.Write("Student's birthday (month): ");
				int month = Int32.Parse(Console.ReadLine());
				Console.Write("Student's birthday (year): ");
				int year = Int32.Parse(Console.ReadLine());
				DateTime birthday = new DateTime(year, month, day);
				// Then we create a new student struct into the next array's hold
				students[i] = new Student(name,adress,birthday);
				Console.WriteLine("------------------------\n");
				// We display all obtained data
				Console.WriteLine("Data for student " + (i+1) + " are the following:");
				Console.WriteLine("Name: " + students[i].stName);
				Console.WriteLine("Adress: " + students[i].stAdress);
				Console.WriteLine("Birthday: {0}/{1}/{2}",
				                  students[i].stBirthday.Day,
				                  students[i].stBirthday.Month,
				                  students[i].stBirthday.Year);
				Console.WriteLine();
				// We'll ask for a new request if there are more holds in the array
				if(i < students.Length - 1){

					char c;
					bool flag = true;

					do{
						Console.Write("You want to fill the next gap? (y/n): ");
						c = (char)Console.Read();
						Console.WriteLine();

						if(c == 'y' || c == 'Y'){
							Console.WriteLine("Let's continue then!");
						}else if(c == 'n' || c == 'N'){
							Console.WriteLine("Ok, data request finished.");
							i = students.Length;
						}else{
							Console.WriteLine("Remember: You have to answer with \'y\' or" +
							                  " \'n\'.");
							continue;
						}

						flag = false;
					}while(flag);

					Console.WriteLine();
				}
			}
		}