Re: Simple IF statement prog/dos ENTER interaction

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 02/15/04

  • Next message: Chris \( Val \): "Re: Convert string to char"
    Date: Sun, 15 Feb 2004 19:01:45 +1100
    
    

    "Chris ( Val )" <chrisval@bigpond.com.au> wrote in message
    news:c0n8e3$17psf9$1@ID-110726.news.uni-berlin.de...

    |
    | int x;
    | cout<< " Enter a number greater than 20 :";
    | cin>> x;
    | {
    | if (x < 20)
    | cout<< "Thank you";
    | else
    | cout<<"Great job ";
    | }
    |
    | {
    | if (x > 20)
    | cout << "Thank you again";
    | else
    | cout<< "Your really not so bad";

    [snip]

    Btw - There is no need to introduce new scopes for your
    'if' statements, and you will probably get into trouble
    early on in your learning by introducing these.

    I would recommend that you play around with 'else if'
    statements as well as 'if', which can help you reduce
    having to include multiple if statements to evaluate
    user input.

    For example:

      if( x < 20 )
          cout<< "Thank you";
      else if( x > 20 )
          cout<<"Great job ";
      else
          cout << "You entered 20 ";

    Additionally, the identifier 'x' is ok for toy programs
    like this, but you should get into the habit of using
    meaningful identifier names to make your code easier to
    understand - initialising your variables is also recommended
    in most cases.

    Cheers.
    Chris Val


  • Next message: Chris \( Val \): "Re: Convert string to char"

    Relevant Pages

    • Re: multiple return values
      ... I don't recommend getting them this way, btw. ... It conses and if all you're ... going to do is pass it to something else, I'd recommend MULTIPLE-VALUE-BIND. ...
      (comp.lang.lisp)
    • Re: MIKE SWISHER ADVICE
      ... these are the chemicals used in my red stars so if you can ... recommend a blue that uses some of the stuff I already have it would be ... Potassium Chlorate ... BTW, chlorate stars took away the big headache of worry about proper ...
      (rec.pyrotechnics)
    • Re: Python blowups w/5.2.1
      ... I would recommend a complete cvsup before compiling. ... Btw your email ...
      (freebsd-questions)
    • Re: Celestron NexStar 80 vs Firstscope 76
      ... >I believe that it is entirely safe to recommend any of the high-end ... someone who is considering a couple of inexpensive 80mm refractors. ... Do the mirrors in these scopes compare favorably to Carl Zambuto mirrors? ... The other day Mike Spooner ...
      (sci.astro.amateur)
    • Re: Scope Quality Question
      ... And there are those who recommend the ... > "big" names in microscopy without entirely stepping other scopes into the ... > made by Swift and the other one made by, for instance, Olympus. ... it is not junk and actually useful for microscopy. ...
      (sci.techniques.microscopy)