home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19429 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.5 KB  |  62 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!hobbes.physics.uiowa.edu!news.iastate.edu!niko
  3. From: niko@iastate.edu (Nikolaus E Schuessler)
  4. Subject: Re: C if else statements HELP
  5. Message-ID: <C0JqG6.Ers@news.iastate.edu>
  6. Sender: news@news.iastate.edu (USENET News System)
  7. Organization: Iowa State University, Ames, IA
  8. References: <1993Jan8.160740.22055@magnus.acs.ohio-state.edu>
  9. Date: Fri, 8 Jan 1993 17:40:46 GMT
  10. Lines: 50
  11.  
  12. In article <1993Jan8.160740.22055@magnus.acs.ohio-state.edu> ctoth@magnus.acs.ohio-state.edu (Christopher M Toth) writes:
  13. >    Hi! I just started learning C and have run into problems with
  14. >'if' and'else' statements. I have a program that I am *trying* to write. The
  15. >basic format is:
  16. >
  17. >    printf ("which do you choose?");
  18. >    scanf("%d", &n);
  19. >    choice#1
  20. >    choice#2
  21. >    choice#3
  22. >    choice#4
  23. >
  24. >    if choice #1
  25. >        printf.....
  26. >    if choice #2
  27. >        printf.....
  28. >    if choice #3
  29. >        printf.....
  30. >    if choice #4
  31. >        printf.....
  32. >
  33.  
  34. how about:
  35.  
  36.     switch (n) {
  37.  
  38.        case 1:
  39.           break;
  40.        case 2:
  41.           break;
  42.        case 3:
  43.           break;
  44.        case 4:
  45.           break;
  46.  
  47.        default:
  48.           break;
  49.     }
  50.  
  51. This will only work on certain types though (ints, chars ...)
  52.  
  53. If you don't already have it, you should get the Kernigan and Richie
  54. C book.
  55.  
  56.  
  57. -- 
  58. Niko Schuessler               
  59. Project Vincent Systems Manager              email: niko@iastate.edu
  60. Iowa State University Computation Center     voice: (515) 294-1672
  61. Ames IA 50011                                snail: 272 Durham 
  62.