Compare commits

...

1 Commits

Author SHA1 Message Date
Wágner András ff21b807f2 my solution 1 year ago
  1. 63
      Program.cs

63
Program.cs

@ -2,6 +2,65 @@
class Program {
static void Main(string[] args) {
// Your code goes here
//1. Declaring bool variables and doing boolean logick
bool a = true;
bool b = true;
bool c = false;
Console.WriteLine("a AND b = " + ( a && b));
Console.WriteLine("a OR b = " + ( a || b));
Console.WriteLine("a AND c = " + ( a && c));
Console.WriteLine("a OR (b AND c) = " + ( a || (b && c)));
Console.WriteLine("(a OR b) AND c = " + ((a || b) && c));
Console.WriteLine("c XOR b = " + ( c ^ b));
Console.WriteLine("a XOR b = " + ( a ^ b));
//2. Asking for bool value and doing boolean logick with it
bool correct = false;
ConsoleKeyInfo cki;
Console.WriteLine("\nEnter 0 or 1.");
//Asking repeatedly until the user gives correct input
while(!correct){
cki = Console.ReadKey(true);
if(cki.KeyChar == '0'){
Console.WriteLine("0 -> False");
b = false;
correct = true;
}
if(cki.KeyChar == '1'){
Console.WriteLine("1 -> True");
b = true;
correct = true;
}
}
Console.WriteLine("a AND b = " + ( a && b));
Console.WriteLine("a OR b = " + ( a || b));
Console.WriteLine("a XOR b = " + ( a ^ b));
//3. Asking for a number (I used double) and checking divisibility
double n;
bool d2 = false;
bool d3 = false;
bool d4 = false;
Console.WriteLine("\nEnter a number.");
//Asking repeatedly until the user gives correct input (while the input cannot be converted to double)
while(!double.TryParse(Console.ReadLine(), out n)){}
if(n%3 == 0){
d3 = true;
}
if(n%4 == 0){
d2 = true;
d4 = true;
}else{
if(n%2 == 0){
d2 = true;
}
}
Console.WriteLine("{0} | 2 = {1}", n, d2);
Console.WriteLine("{0} | 3 = {1}", n, d3);
Console.WriteLine("{0} | 4 = {1}", n, d4);
//Waiting for input before closing
Console.ReadLine();
}
}
}
Loading…
Cancel
Save