# Computer Science homework help?

Hello! this is my first semester studying computer science and I'm finding it quite difficult as it's entirely online but my professors give such small lectures. Right now I'm taking an algorithm class and I just want to make sure I have something correct if anyone can help!

the prompt is to Design a program that reads a collection of positive and negative numbers and multiplies only the positive integers. Loop exit should occur when three consecutive negative values are read. "I put my input as "input number double"so when I start my while loop, can it just say "while number > 0" for the positive integers or does the "> 0" imply that decimals bigger than 0 but less than 1 can be entered? Thanks in advance! (Also please don't give me the answer to the whole problem, I just want that simple question answered)

### 6 Answers

- 2 weeks ago
ou can do something like

countx =0

multiplex=0

while(countx<3){

get input

If (input<0) {

countx++ }

else {

countx=0;

multiplex*=input;

}

}

- TasmLv 63 weeks ago
You can do something like

countx =0

multiplex=0

while(countx<3){

get input

If (input<0) {

countx++ }

else {

countx=0;

multiplex*=input;

}

}

- Daniel HLv 54 weeks ago
What about 0?

while (number >= 0)

However this only accounts for one positive numbercounter = 0;do{ read number; if (number < 0) counter = counter + 1; else counter = 0;}while (counter < 3)

- husoskiLv 74 weeks ago
The expression "number > 0" will be true whenever number is positive. If that variable can hold a fraction, then fractions greater than 0 by any amount will compare as greater than 0.

That's true no matter where the comparison is done, in a while statement, if or elsif statement, or in anywhere else a boolean expression is allowed.

- How do you think about the answers? You can sign in to vote the answer.
- mark_pocLv 64 weeks ago
I forgot why, but using fractional numbers for the control variable of loops is a no no. I think it has something to do with the way the numbers are rounded during calculation. Maybe someone could better answer.