-2

I want to apply more than one while loop so it can do the calculations below but within the given range. eg. p_fifties-= fifties must calc while it is between 0 < x < 10. So when it's more than 10 it must do the next calculation.

I was wondering if I can add more than one while loop at the end so it gives a range for each calculation. Is it possible?

  do{
  p_fifties  -= fifties; 
  p_twenties -= twenties;
  p_tens -= tens;
  } while();
enedil
  • 1,605
  • 4
  • 18
  • 34
Kadir
  • 63
  • 1
  • 13

4 Answers4

2

The question is a bit unclear. The language accepts only a single condition in the while( ... ), but a condition can be built by combining several sub-conditions with logical operators. Example:

do {
  p_fifties  -= fifties; 
  p_twenties -= twenties;
  p_tens -= tens;
} while( p_fifties >= 20 && ( p_twenties >= 5 || p_tens > 0 ) );

where && is a logical and and || is a logical or.

Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
1

You question is a bit unclear,

but do you mean =>

All counters reach 0:

do{
  p_fifties  -= fifties; 
  p_twenties -= twenties;
  p_tens -= tens;
  } while
(p_fifties > 0 &&  
  p_twenties > 0 &&
  p_tens > 0)

Any one counter reaches 0:

do{
  p_fifties  -= fifties; 
  p_twenties -= twenties;
  p_tens -= tens;
  } while
(p_fifties > 0 ||  
  p_twenties > 0 ||
  p_tens > 0)
Croc Studio
  • 141
  • 3
1

You can use &&

 do
 {
     p_fifties  -= fifties; 
     p_twenties -= twenties;
     p_tens -= tens;
  } while(p_fifties>0 && p_twenties>0 &&  p_tens>0);
RostakaGmfun
  • 487
  • 6
  • 21
0

As many as you want using logic operators

If there are too many conditions consider using a function call in the while loop condition.

keyser
  • 18,829
  • 16
  • 59
  • 101
Leon
  • 12,013
  • 5
  • 36
  • 59