Thread: SENTINEL question

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    SENTINEL question

    I have a program that prints out the smallest of 3 numbers. I'm trying to use a combination of "0 0 0" as my sentinel control to stop the program. However if I define a SENTINEL constant as 0 and then plug it into my loop, I get a syntax error. So I'm using the way below. (Becuase this is for school some of it has been omitted for reasons I'm sure everyone is aware of

    Code:
    #include <stdio.h>
    
    int main()
    {
      double num1, num2, num3, smallest;
    
          printf("Enter three numbers: "); 
          scanf("%lf%lf%lf", &num1, &num2, &num3);
    
           while (num1 !=0 && num2 !=0 && num3 != 0)
             {
         
               if (num1 < num2 && num1 < num3) 
                 {
                   smallest = num1;
                 }
               else if (...)
                 {
                   ...;
                 }
               else if (...)
                 {
                   ...;
                 }
     
               printf("The smallest number was %.3lf\n", smallest);
    
               printf("Enter three numbers: ");
               scanf("%lf%lf%lf", &num1, &num2, &num3);
            }
      return 0;
    }
    The problem is if I enter 0 as any of the 3 numbers it stops the program. I only want it to stop if 0 0 0 is entered. Can someone help me out with this?

    Also, how come I get a syntax error if I replace the "0" with SENTINEL?

    thanks

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    while ( !(num1 == 0 && num2 == 0 && num3 == 0) )
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    2
    beautiful thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM