- #36
Travian
- 64
- 0
I will use a boolean expression.
if largestNumber < Number then
largestNumber = Number + largestNumber
else
hmmm
D
if largestNumber < Number then
largestNumber = Number + largestNumber
else
hmmm
![Hilarious :DD :DD](/styles/physicsforums/xenforo/smilies/hilarious.png)
If by "setup" you mean the problem statement, you are confusing the requirements of the problem statements with an implementation. This problem can and should be done without arrays. That's the point that I and several other responders have been making.╔(σ_σ)╝ said:Again I would emphasize that given the setup that OP gave called for arrays.
Then you and I disagree. In my view, Travian was heading down the wrong track. When that happens, the best thing is not to help him go in the wrong direction, but to steer him in the right direction.╔(σ_σ)╝ said:I even thought that was the direction OP was going to. In this original post he was using a loop to cycle through an array he didn't create. Besides, i thought it would be better if i went along with OP thought process instead of giving him a totally different approach.
╔(σ_σ)╝ said:Mark44 it was not a flawed interpretation . I belief he had the right idea but the execution was not satisfactory.
Travian said:I will use a boolean expression.
if largestNumber < Number then
largestNumber = Number + largestNumber
else
hmmmD
Mark44 said:Try it with actual numbers.
1) Let largestNumber = 25 and Number = 28
What should happen?
2) Let largestNumber = 25 and Number = 23
What should happen?
Declare Counter as integer
Declare Number as float
Delare largestNumber as integer
Set Counter = 0
Set Number = -1
Set largestNumber = 0
Display "Enter a number. Enter a zero to finish"
WHILE Number != 0
Get Number
IF Number > 0 THEN
Counter = Counter + Number
IF largestNumber < Number THEN
largestNumber = largestNumber + Number
ENDIF
ENDIF
ENDWHILE
Display "The sum of positive numbers is: " + Counter
Display “The largest number is “ + largestNumber
Mark44 said:Try it with actual numbers.
1) Let largestNumber = 25 and Number = 28
What should happen?
2) Let largestNumber = 25 and Number = 23
What should happen?
No, IF statement is what you want. The examples above weren't necessarily in sequence. The idea was that in the first example, largestNumber should be reset. In the second example, largestNumber shouldn't be reset.Travian said:1) largestNumber becomes 28
2) largestNumber cannot be 25, because it became 28. i should have used while loop i think, not if statement.
IF Number > largestNumber THEN
largestNumber = Number
ENDIF
Declare Counter as integer
Declare Number as float
Delare largestNumber as integer
Set Counter = 0
Set Number = -1
Set largestNumber = 0
Display "Enter a number. Enter a zero to finish"
WHILE Number != 0
Get Number
IF Number > 0 THEN
Counter = Counter + Number
[b]IF (Number > largestNumber) THEN
largestNumber = Number
ENDIF[/b]
ENDIF
ENDWHILE
Display "The sum of positive numbers is: " + Counter
Display “The largest number is “ + largestNumber