The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Difference between if [[ ]] and if [ ] statements rony_daniel Shell Programming and Scripting 1 09-19-2007 06:11 AM
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 05:59 AM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 08:07 AM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 04:08 PM
if statements lilas UNIX for Dummies Questions & Answers 2 03-22-2001 11:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-01-2008
pwanda pwanda is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 10
Exclamation if statements

This is for a program I have to do to calculate the day of the week.
I need to write an if statement that will do the following:

Code:
if day is 29 and year is odd, don't calculate day
Code:
if ( day == 29 && year == ??? )
I know how to do it for the day but I don't know how to do it for the year.
  #2 (permalink)  
Old 11-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
What language are you writing this programme in?
  #3 (permalink)  
Old 11-02-2008
pwanda pwanda is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 10
In C.
  #4 (permalink)  
Old 11-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
This should do it:

Code:
if ( day == 29 && year % 2 )
year % 2 is 0 (i.e. false) if the year is even, and 1 (i.e. true, as is any non-zero value in C) if the year is odd. % is the "modulus" or "remainder" operator.
  #5 (permalink)  
Old 11-02-2008
pwanda pwanda is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 10
Smile

Oh. That makes sense.

Thank you!
Closed Thread

Bookmarks

Tags
csh, if statement

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0