Run if statement block if either one of the conditionals are true [closed]
I need to write an if statement block that will run if the value entered is less than $5.65 or greater than 50. How can I do this?
using System;
using static System.Console;
namespace HomeWork1
{
internal class Program
{
static void Main(string[] args)
{
WriteLine ("What is your hourly pay rate");
double rate;
string input;
input = ReadLine();
rate =Convert.ToDouble(input);
WriteLine("Your hourly pay rate {0}", rate);
if (rate < 5.65 )
{
Console.WriteLine("Error entering your pay rate");
}
}
}
}
}
Solution 1:
Use the or operator ||
to make this work. The or operator ||
will execute the if block if either one of the conditions are true.
if (rate < 5.65 || rate > 50)
{
Console.WriteLine("Error entering your pay rate");
}