Logical Data
with an Illogical Assignment
In this lesson you are going to have the opportunity to interact with operators and Logical Data. Somtimes in code the things that you need to test for can be very specific and strange if you don't know the circumstances of why you are trying to get them. This is exactly the case in the assignment. You are being asked to utilize operators to test for specific values.
Good luck and enjoy... Believe it or not this is really not all that hard.
Good luck and enjoy... Believe it or not this is really not all that hard.
The Code
using System;
namespace Parenthesis
{
class Program
{
static void Main()
{
{
bool answer;
Console.Write("Please enter a number ");
string strValue = Console.ReadLine();
int value = Convert.ToInt32(strValue);
// write your code here
Console.WriteLine("The number you put in " + strValue + " is " + answer);
}
}
}
}
namespace Parenthesis
{
class Program
{
static void Main()
{
{
bool answer;
Console.Write("Please enter a number ");
string strValue = Console.ReadLine();
int value = Convert.ToInt32(strValue);
// write your code here
Console.WriteLine("The number you put in " + strValue + " is " + answer);
}
}
}
}
Example Videos
The conditions
Take a look at the code below: it reads an integer value, and is then ready to perform a complicated test and print the answer – it may be True or it be False.
We need a number whose value:
1. is greater than or equal to 0 and less than 10, or
2. multiplied by 2 is less than 20 and subtracted by 2 is greater than minus 2, or
3. reduced by 1 is greater than 1 and divided by 2 is less than 10, or
4. is equal to 111.
Write the above condition in the form of an expression accepted by the C# language and assign its result to the answer variable. Test your code using the data we've provided.
Helpful hints:
Greater than looks like this >
Less than looks like this <
Greater than or equal to looks like this >=
Less than or equal to looks like this <=
Reduced/Subtract looks like this -
Increased/Added looks like this +
Multiplied looks like this *
Divide by looks like this /
Testing to see if something is Equal to something else looks like this ==
Testing to see if something is Not Equal to something else looks like this !=
Or looks like this ^ (it is a Shift 6)
And looks like this && (it is a double Shift 7)
We need a number whose value:
1. is greater than or equal to 0 and less than 10, or
2. multiplied by 2 is less than 20 and subtracted by 2 is greater than minus 2, or
3. reduced by 1 is greater than 1 and divided by 2 is less than 10, or
4. is equal to 111.
Write the above condition in the form of an expression accepted by the C# language and assign its result to the answer variable. Test your code using the data we've provided.
Helpful hints:
Greater than looks like this >
Less than looks like this <
Greater than or equal to looks like this >=
Less than or equal to looks like this <=
Reduced/Subtract looks like this -
Increased/Added looks like this +
Multiplied looks like this *
Divide by looks like this /
Testing to see if something is Equal to something else looks like this ==
Testing to see if something is Not Equal to something else looks like this !=
Or looks like this ^ (it is a Shift 6)
And looks like this && (it is a double Shift 7)
The Results
Example input
-2
Example output
THAT'S NOT TRUE
Example input
0
Example output
THAT'S TRUE
Example input
4
Example output
THAT'S TRUE
Example input
10
Example output THAT'S TRUE
Example input
22
Example output
THAT'S NOT TRUE
Example input
100
Example output
THAT'S NOT TRUE
Example input
111
Example output
THAT'S TRUE
-2
Example output
THAT'S NOT TRUE
Example input
0
Example output
THAT'S TRUE
Example input
4
Example output
THAT'S TRUE
Example input
10
Example output THAT'S TRUE
Example input
22
Example output
THAT'S NOT TRUE
Example input
100
Example output
THAT'S NOT TRUE
Example input
111
Example output
THAT'S TRUE