LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2005, 10:56 AM   #1
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Rep: Reputation: 0
an if statement that has two variables


i am working in c++ and i need to make an if statement that says if a and b are equivelent to 0 then...

the only way that I could think of was
if (a==0) (b==0)
{...
}

this however does not work.

thanks for all your help!
 
Old 10-04-2005, 10:58 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Code:
if ( (a==0) && (b==0) )
{
  ...
}
Equivalently:
Code:
if ( (!a) && (!b) )
{
  ...
}
PS:
I'd really discourage you from putting code after your start ("{") brace:
http://www.gnu.org/prep/standards/
http://geosoft.no/development/cppstyle.html
http://www.chris-lott.org/resources/cstyle/
etc etc ad nauseum...

PPS:
Here are the two variants you'll see most often: I'd choose one of these:
Code:
// K & R, Java:
  if (x == y) {
    << do something >>
  }

Code:
// ANSI C/C++, .Net:
  if (x == y) 
  {
    << do something >>
  }

Last edited by paulsm4; 10-04-2005 at 11:09 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch Statement w/ Constant Variables Mistro116@yahoo.com Programming 1 10-04-2005 07:48 AM
the FOR statement (C) sk84blood813 Programming 3 12-09-2004 08:25 AM
For Statement bendeco13 Linux - General 6 10-31-2004 05:31 PM
If Statement junjem0702 Programming 4 08-23-2004 09:49 AM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 11:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration