Click here to Skip to main content
15,122,845 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

C#
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 20: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

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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900