Friday, 15 April 2011

conditions for multiple variables in while loop c++ -


I am trying to show the "invalid input" to the loop of my timeline for a short while for the 3 variables I am just starting with C ++, so I'm not the best at trying to show what I want, but here it is in my condition.

  while (children 1, children 2, children 3) & lt; 1 || (Children 1, children 2, children 3) & gt; 100) cout & lt; & Lt; "Invalid Input"; Return 0;  

It is easiest to express each requirement separately:

  while (Children 1 & Lt; 1; Children 2 & Lt; 1; Children 3 & lt; 1; Children 1 & gt; 100; Children 2 & gt; 100; Children 3 & gt; 100) Std :: cout & lt; & Lt; "Invalid input \ n";  

AC + 11 options are:

  #include & lt; Algorithm & gt; ... while std :: min ({children 1, children 2, children 3}) & lt; 1 || std :: max ({children1, children2, kids3}) gt; 100) std :: cout & lt ; & Lt; "Invalid input \ n";  

FWID, if you have a number in a std :: vector - arguably more elegant - option will be available:

  Std :: vector & lt; Integer & gt; children; Children.push_back (23); Children.push_back (123); Children.push_back (13); // ... Still many people like you ... while (Study :: any :: std :: start (children), std :: end (children), [] (int n) {return n & Lt; 1 || n & gt; 100;})) std :: cout & lt; & Lt; "Invalid input \ n";  

Note that if you select while , if , or Braces needs to be used:

  int retries_available = 3; While {std :: any_of (std :: start (children), std :: end (children), [] (int n) {return n <1; n> 100;})) {std: : Cout & lt; & Lt; "Invalid input \ n"; If (retries_available-- == 0) returns 0; Get_new_values_for (children); }  

No comments:

Post a Comment