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

J

James

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
 
C

Clif Penn

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".
 
M

Mike Wahler

James said:
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
 
J

Julian V. Noble

James said:
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
(e-mail address removed)
^^^^^^^^^^^^^^^^^^
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".
 
D

dfg

Julian said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top