Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 28th, 2011, 11:04 PM   #1
Learner2011
Newbie
 
Join Date: Jun 2011
Posts: 4
Rep Power: 0 Learner2011 is on a distinguished road
How to use the bool?

I am really new to programming so please bear with me if my question sounds really stupid. I am trying to use the boolean to decide as in the following part:
c# Syntax (Toggle Plain Text)
  1. bool B;
  2. string sString;
  3. Console.WriteLine ("Do you want to continue? Y/N");
  4. sString = Console.ReadLine();
  5. if (B = (sString = "Y"))
  6. {
  7. Console.WriteLine ("What else do you want to do?");
  8. Console.Read();
  9. }
but whenever I am trying to compile the code, it says "cannot implicitly convert type 'string' to 'bool'. Where am I going wrong? How should I write the if... structure correctly. Please help.

Last edited by Ancient Dragon; Jun 28th, 2011 at 11:05 PM. Reason: add code tags
Learner2011 is offline   Reply With Quote
Old Jun 28th, 2011, 11:08 PM   #2
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: How to use the bool?

You really don't need the boolean in that expression. Just if( sString == "Y"). But if you really do want to use the boolean then the correct thing is if( (B = (sStirng == "Y")) ). Notice that = is an assignment operator, while == is a logical operator.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline   Reply With Quote
Old Jun 28th, 2011, 11:16 PM   #3
Learner2011
Newbie
 
Join Date: Jun 2011
Posts: 4
Rep Power: 0 Learner2011 is on a distinguished road
Re: How to use the bool?

Thanks Ancient Dragon. That works perfectly.
Learner2011 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bool function robbiewoods05 C++ 3 Jun 13th, 2011 1:45 PM
curious problem with bool variable and references. NiGhtMarEs0nWax C++ 3 May 1st, 2010 9:02 PM
finding prime using bool gmann145 C++ 5 Feb 14th, 2008 5:19 PM
Switching bool values Booooze C# 5 Apr 21st, 2007 12:07 AM
Defining a bool type nnxion C 6 Oct 7th, 2005 8:39 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC