I'm new at C, and I'm having problems with descisions and loops

Discussion in 'C Programming' started by James, Nov 22, 2003.

  1. James

    James Guest

    Hi,
    I need to create a program that prompts the user to either select
    options 1,2,3 or 4, or type end to end the program. The user must be
    able to select any option as may times as he or she wants, unitl
    he/she types end. I've got a switch going, (as well as using a while
    to repeat the switch) and I'm aware it only accepts ints, so i was
    thinking of putting an if/else statement around it, something like if
    the input is an int, do the switch, else close the program. can anyone
    help me?
    Thanks,

    James
     
    James, Nov 22, 2003
    #1
    1. Advertising

  2. James

    Eric Guest

    James <> wrote:

    > can anyone help me?


    Most certainly. Why don't you post what you've got.


    --
    == Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
    "Therefore the considerations of the intelligent always include both
    benefit and harm." - Sun Tzu
    == Insults, like violence, are the last refuge of the incompetent... ===
     
    Eric, Nov 22, 2003
    #2
    1. Advertising

  3. James

    Clif Penn Guest

    On 22 Nov 2003 08:23:51 -0800, (James) wrote:

    >Hi,
    >I need to create a program that prompts the user to either select
    >options 1,2,3 or 4, or type end to end the program. The user must be
    >able to select any option as may times as he or she wants, unitl
    >he/she types end. I've got a switch going, (as well as using a while
    >to repeat the switch) and I'm aware it only accepts ints, so i was
    >thinking of putting an if/else statement around it, something like if
    >the input is an int, do the switch, else close the program. can anyone
    >help me?
    >Thanks,
    >
    >James


    When I have written similar programs, I just use "5" as an aption for
    "end".
     
    Clif Penn, Nov 22, 2003
    #3
  4. James

    Mike Wahler Guest

    "James" <> wrote in message
    news:...
    > Hi,
    > I need to create a program that prompts the user to either select
    > options 1,2,3 or 4, or type end to end the program. The user must be
    > able to select any option as may times as he or she wants, unitl
    > he/she types end. I've got a switch going, (as well as using a while
    > to repeat the switch) and I'm aware it only accepts ints, so i was
    > thinking of putting an if/else statement around it, something like if
    > the input is an int, do the switch, else close the program. can anyone
    > help me?
    > Thanks,


    I once called my dentist when I had a toothache, but darn him,
    he insisted that before he could fix it, he needed to actually
    look into my mouth.

    -Mike
     
    Mike Wahler, Nov 22, 2003
    #4
  5. James wrote:
    >
    > Hi,
    > I need to create a program that prompts the user to either select
    > options 1,2,3 or 4, or type end to end the program. The user must be
    > able to select any option as may times as he or she wants, unitl
    > he/she types end. I've got a switch going, (as well as using a while
    > to repeat the switch) and I'm aware it only accepts ints, so i was
    > thinking of putting an if/else statement around it, something like if
    > the input is an int, do the switch, else close the program. can anyone
    > help me?
    > Thanks,
    >
    > James


    Write the program as a finite state machine rather than as decisions cum
    loops. It will be much cleaner.

    --
    Julian V. Noble
    Professor Emeritus of Physics

    ^^^^^^^^^^^^^^^^^^
    http://galileo.phys.virginia.edu/~jvn/

    "God is not willing to do everything, and thereby take away that
    share of glory that rightfully belongs to ourselves."

    -- N. Machiavelli, "The Prince".
     
    Julian V. Noble, Nov 23, 2003
    #5
  6. James

    dfg Guest

    Julian V. Noble wrote:

    > James wrote:
    >
    >>Hi,
    >>I need to create a program that prompts the user to either select
    >>options 1,2,3 or 4, or type end to end the program. The user must be
    >>able to select any option as may times as he or she wants, unitl
    >>he/she types end. I've got a switch going, (as well as using a while
    >>to repeat the switch) and I'm aware it only accepts ints, so i was
    >>thinking of putting an if/else statement around it, something like if
    >>the input is an int, do the switch, else close the program. can anyone
    >>help me?
    >>Thanks,
    >>
    >>James

    >
    >
    > Write the program as a finite state machine rather than as decisions cum
    > loops. It will be much cleaner.


    He is a beginner though. Is a Finite state machine easy enough to
    understand for someone new to programming?
     
    dfg, Nov 23, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. judith
    Replies:
    16
    Views:
    1,077
    Chris Uppal
    Oct 16, 2006
  2. StephQ
    Replies:
    8
    Views:
    297
    StephQ
    Feb 28, 2007
  3. Interrupt

    problems with logic operations within loops

    Interrupt, Jan 26, 2010, in forum: C Programming
    Replies:
    46
    Views:
    979
    Phil Carmody
    Jan 30, 2010
  4. Me
    Replies:
    2
    Views:
    263
  5. Replies:
    2
    Views:
    509
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page