Click here to Skip to main content
15,112,483 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am not getting any output here. Have tried a few different variations - I get no errors, but no output. The assignment is to combine multiple Boolean values (false) to get the output "Let's go outside." Any help would be appreciated for a quick fix. thank you!

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace boolletsgooutside
{
    class boolletsgooutside
    {
        static void Main(string[] args)
        {
            // declare boolean values
            bool icyRain = true;
            bool tornadoWarning = true;
            string name = "Let's go outside";

            if  ((!icyRain) & (!tornadoWarning))
            {
               Console.WriteLine("{0}";, name);
            }
        }
    }
}
Posted
Updated 22-Nov-15 14:43pm
v2
Comments
[no name] 22-Nov-15 19:46pm
   
if ((!icyRain) & (!tornadoWarning))
Check this line. Hint ! means "not". Also do you really want & or &&.
Member 12141172 22-Nov-15 19:49pm
   
Thank you for your response! I am still not sure what the problem is:
I tried it both with & and &&, and the output is still blank.
Yes, I want both values to be false.
Sergey Alexandrovich Kryukov 22-Nov-15 20:04pm
   
1) Programming is not done by trying. Simply read C# manual and understand it, check up your understanding on code exercises.
2) No, you did not try what you could have tried.
3) Use the debugger in case of even slightest concern of your runtime; always do it before you ask a question.
4) Read my answer.
—SA
Member 12141172 22-Nov-15 20:17pm
   
ok.

If you look at the code
VB.NET
static void Main(string[] args)
{
// declare boolean values
bool icyRain = false;
bool tornadoWarning = false; 

        if  ((icyRain) && (tornadoWarning))
        {
           Console.WriteLine("Let's go outside!");
        }
    }
}

}


The if condition will be evaluated as
if(false) && (false), which will be equal to if(false).

that means, only the code in the else part will be executed here (unfortunately you didn't add any else part.

Also, please add a Console.Read() to hold the console window, until you press any key!
   
v2
Comments
Member 12141172 22-Nov-15 21:16pm
   
thank you!!
YES, need to add the Console.ReadLine(); (bad programming form)
Liju Sankar 22-Nov-15 23:49pm
   
Happy to see that it helped :)
thank you, definitely appreciate the feedback.
I must still be missing something, because if I do it this way, I still have the same problem of no output. Frankly, no matter how I've played with it, the output is blank. I'm a beginner, so I am missing something.

static void Main(string[] args)
{
// declare boolean values
bool icyRain = false;
bool tornadoWarning = false;

if ((icyRain) && (tornadoWarning))
{
Console.WriteLine("Let's go outside!");
}
}
}
}
   
Comments
BillWoodruff 22-Nov-15 21:38pm
   
Your boolean statement above says, in effect: ONLY if there is icyrain and a tornado warning, print "let's go outside" ... but your variables imply there is no icyrain or tornado warning ... why should you be surprised that it prints nothing ?
Try with the logical and
C#
if  ((!icyRain) && (!tornadoWarning))

Otherwise, no output is perfectly normal, it is what you asked.
This may be closer to your intend:
C#
bool icyRain = false;
bool tornadoWarning = false;
if  ((!icyRain) && (!tornadoWarning))
   
It happens because your "if" condition is false; and it false because it is composed out of two Boolean operators, which are always true.

By the way, 1) it makes no sense to define variables which you never change; in such case, make them constants, 2) use && Boolean operator instead of & read in a C# manual about the difference between them; && is shortcut, but be careful if operands are function, optimizing out one of the calls can surprise you.

—SA
   
Comments
Member 12141172 22-Nov-15 20:11pm
   
I tried adding an else statement and it also didn't work.
Member 12141172 22-Nov-15 20:16pm
   
Even like this, I get no output (I know the Boolean values should always be true).

static void Main(string[] args)
{
// declare boolean values
bool icyRain = true;
bool tornadoWarning = true;

if ((icyRain) & (tornadoWarning))
{
Console.WriteLine();
}
else if ((!icyRain) && (!tornadoWarning))
{
Console.WriteLine("Let's go outside!");
}
}
}
}
Sergey Alexandrovich Kryukov 22-Nov-15 20:32pm
   
You are thinking along the wrong lines. Read my comment to the question. The "problem" is more than trivial.
—SA

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