Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

If

 
0
  #1
Oct 23rd, 2006
Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90 .


if(outsdieTemperature > 90){
shelfLife-4;
}

something is wrong..can you help..?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: If

 
0
  #2
Oct 23rd, 2006
I strongly suggest that you read through the tutorial.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

Re: If

 
0
  #3
Oct 23rd, 2006
Originally Posted by DavidRyan View Post
I strongly suggest that you read through the tutorial.


i'll try ..!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

Re: If

 
0
  #4
Oct 23rd, 2006
if(outsideTemeratures > 90){
shelfLife=shelfLife-4;
}


i have to use the outsideTemperature variable

i dont understand...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: If

 
0
  #5
Oct 23rd, 2006
Let's have a look at what is happening in the two blocks you have posted then.
Block 1:
  1. if(outsdieTemperature > 90){
  2. shelfLife-4;
  3. }
Block 2:
  1. if(outsideTemeratures > 90){
  2. shelfLife=shelfLife-4;
  3. }
In Block 1, you are saying if the temperature is above 90 degrees, subtract 4 (I'll assume days) days from the shelflife.Meanwhile, in Block 2, you are saying if the temperature is above 90 degrees, subtract 4 days from the shelflife and let that value be called shelflife from now on.

IE, the outside temperature is 92 degrees and the current value of shelflife is 30 days. After Block 1, shelflife is still equal to 30 days, because you haven't told the program to actually change the value stored in the variable. After Block 2 however, you have told the program to change the value stored in the variable, and shelflife is now equal to 26 (IE it's previous value minus 4 days).
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

Re: If

 
0
  #6
Oct 23rd, 2006
i understand that its missing a variable..
i cant find which variable to use....
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: If

 
0
  #7
Oct 23rd, 2006
Originally Posted by THK View Post
i understand that its missing a variable..
i cant find which variable to use....
Have you initialised the variable Shelflife before the if statement?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 15
Reputation: THK is an unknown quantity at this point 
Solved Threads: 0
THK's Avatar
THK THK is offline Offline
Newbie Poster

Re: If

 
0
  #8
Oct 23rd, 2006
yes

int outsideTemperature = 80, shelfLife=10;
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: If

 
0
  #9
Oct 23rd, 2006
There are now 2 possibilities. I'll get to them after a bit of background.

If the variable shelf life isn't being changed, look at the conditional (the bit after If which tells the program the circumstances in which to run the statements in the {}).

In this case, the conditional is (outsideTemeratures > 90). If this evaluates as True, the variable shelfLife will be changed, if it evaluates as False, the variable shelfLife will not be changed.

Now, the possibilities. The first is that you made a typo when you wrote the If block. You have three different spellings of what seems to be the same variable (outsideTemperature in the declaration; outsideTemeratures in the second try at the If block and outsdieTemperature in the first try). Check that your spelling of each variable is the same throught the program.

If the program still doesn't change the value of shelfLife after you have checked your spelling, then answer me this:
Is the temperature outside actually greater than 90 degrees?
You have initialized the temperature variable as 80 degrees, and that is lower than 90 degrees. If the value of the outsideTemperature is not changed between the initialisation and the If block then the If block's conditional (see paragraph 3) will evaluate as False (ie the temperature outside is not greater than 90 degrees) and the statements inside the If block will be skipped.
Last edited by DavidRyan; Oct 23rd, 2006 at 9:35 pm.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC