Click here to Skip to main content
14,301,033 members
Rate this:
Please Sign up or sign in to vote.
See more:
Conditional statement that if i is greater than or equal to j output result1. if i is less than two times the value of j output result2.

What I have tried:

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            string output = "";
            const string result1 = "Foo";
            const string result2 = "Bar";
            int i = 100;
            int j = 100;


  if (i>=j)
       {
       output = result1 + result2 ;
         
         }
       if (i<(2*j))
         
         {
          output = result2;
          }
          
    Console.Write(output);
        }
    }
}
Posted
Updated 1-Dec-18 19:06pm
v2
Comments
Patrice T 1-Dec-18 19:15pm
   
This is not a question.
David_Wimbley 1-Dec-18 22:15pm
   
What is your problem?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

What you need to think about is exactly what you are trying to do:
If i is greater than or equal to j output result1. Otherwise, if i is less than two times the value of j output result2.

So what you need to code is just that:
const string result1 = "Foo";
const string result2 = "Bar";
int i = 100;
int j = 100;


string output = "";
if (i >= j)
    {
    output = result1;
    }
else if (i < (2 * j))
    {
    output = result2;
    }
Console.Write(output);
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100