Thread: Average question

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    50

    Average question

    How do you put a case ' ': in a while loop?
    Could you give an example

    thanks
    jay

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    why are you putting a case in a while loop? a case should be in a switch

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    50
    Can you give a switch w/ case example then?

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    int choice;
    printf("%d", "enter an int between 1 and 3");
    sscanf("%d", &choice);
     
    switch(choice)
    {
      case 1:
    	 //do something here
    	 break;
      case 2:
    	 //do something else here
    	 break;
      case 3:
    	 //do something really weird here
    	 break;
      default:
    	 break;
    }
    sorry, been a long time since I did any C I/O. The printf and sscanf syntax isn't the important part anyway.
    You're only born perfect.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sure you can put a case in a while loop:
    Code:
    while( c != 'q' )
    {
        switch( c )
        {
            case 'a': printf("You selected \'a\'.\n" ); break;
            case 'b': printf("You selected \'b\'.\n" ); break;
            default: printf("You didn't select anything useful.\n");
        }
    }
    Now in this case you'd want to have something in there that actually changes the value of c, but you get the idea.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by elad
    Code:
    printf("%d", "enter an int between 1 and 3");
    Code:
    printf("enter an int between 1 and 3\n");
    now it's ok

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. fgets question
    By mattyg in forum C Programming
    Replies: 2
    Last Post: 12-01-2008, 04:25 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. modal average
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2001, 01:18 PM