Skip to content

Instantly share code, notes, and snippets.

@themaleem
Last active March 26, 2023 15:47
Show Gist options
  • Save themaleem/eb87fce7fe69295dac5c5b7ae5434d55 to your computer and use it in GitHub Desktop.
Save themaleem/eb87fce7fe69295dac5c5b7ae5434d55 to your computer and use it in GitHub Desktop.
week3 c# tut
// int speed = 25;
// System.Console.WriteLine("The car was" + "Travelling at the speed of " + speed + " MPH");
// int age;
// age = 25;
// age++;
// age += 1;
// age--;
// age -= 1;
// // in two years, age will be age + 2
// age += 2; // 27
// age -= 2; // 25
// // System.Console.WriteLine(age);
// double age2 = Convert.ToDouble(age);
// age2 /= 2; // 12 not 12.5
// age *= 2; // 24
// System.Console.WriteLine(age);
// 25.0 / 2; // 12.5
// true false
// true and true true
// true and false false
// false and false false
// false and true false
// true or true true
// true or false true
// false or false false
// false or true true
// 1 + 2 + 3 + 4
// 3 + 3 + 4
// 6 + 4
// (false and true) or (true or false ) and ( false or false) and (true and true)
// (false or true) and (false and true)
// true and false
// false
// false or true or false ^ true or false and true and true
// true or false ^ true or false and true and true
// true ^ true or false and true and true
// true or false and true and true
// true and true and true
// true and true
// true
// false or true or false and false or false and true and true
// true or false and false or false and true and true
// true and false or false and true and true
// false or false and true and true
// false and true and true
// false and true
// false
// either peace and chidinma to be available before we hold a meeting
// if chidinma and peace
// hold the meeting
// else if chidinma or peace
// hold the meeting
// else
// no meeting
// always go to school monday to friday but not on weekends
// while the day is monday to friday
// go to school
// day is saturday
// don't go to school
// break
// int count = 2;
// int total = 10;
// while (count < total)
// {
// Console.WriteLine("Count " + count);
// count++;
// System.Console.WriteLine("Count is now " + count);
// if (count == 7)
// break;
// }
// do
// {
// Console.WriteLine("Count " + count); // Count 2
// count++; // count = count + 1 = 3
// }
// while (count < total);
// string name = "Chidinma";
// for (int val = 0; val < name.Length; val = val + 2)
// {
// System.Console.WriteLine(name[val]);
// }
// foreach (var character in name)
// {
// System.Console.WriteLine(character);
// }
// string[] DayOfWeek;
// DayOfWeek = new string[7];
// DayOfWeek[0] = "Mon";
// DayOfWeek[1] = "Tue";
// DayOfWeek[2] = "Wec";
// DayOfWeek[3] = "Thur";
// DayOfWeek[4] = "Fri";
// DayOfWeek[5] = "Sat";
// DayOfWeek[6] = "Mon";
// string[] daysOfWeek = { "Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun" };
// int item = Convert.ToInt32(Console.ReadLine());
// switch (item)
// {
// case 1:
// Console.WriteLine("case 1");
// break;
// case 5:
// Console.WriteLine("case 5");
// break;
// case 9:
// Console.WriteLine("case 9");
// break;
// default:
// Console.WriteLine("No match found");
// break;
// }
public static bool compare()
{
// Write a method that takes two numbers as input and returns true or false if the two numbers are equal.
Console.WriteLine("Input two numbers ");
Console.Write("Input first number: ");
int number1;
number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input second number: ");
int number2;
number2 = Convert.ToInt32(Console.ReadLine());
return number1 == number2;
}
public static void login()
{
// Write a method that takes userid and password as input (type string). After 3 wrong attempts, user will be
// rejected. Method must print appropriate message for success and for running out of tries.
// Hint: You need an if statement that checks the two inputs against set values (For example userId = “mo”,
// password = “secret” – the inputs are compared to “mo”, and “secret”). Also, you need to have a counter to
// record number of attempts. You need a while loop to make sure up to 3 attempts are allowed.
for (int counter = 0; counter < 3; counter++)
{
Console.Write("userid: ");
string userid = Console.ReadLine();
Console.Write("password: ");
string password = Console.ReadLine();
if (userid == "mo" && password == "secret")
{
System.Console.WriteLine("Login is successful");
break;
}
else
{
System.Console.WriteLine("Login is unsuccessful");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment