Working with "Sentinel-Exit (-1)".. :{

This is a discussion on Working with "Sentinel-Exit (-1)".. :{ within the C Programming forums, part of the General Programming Boards category; Need to "Exit Stage Left" on this small program... I am working out of "C - How to program"... Working ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Location
    Aurora, CO
    Posts
    9

    Working with "Sentinel-Exit (-1)".. :{

    Need to "Exit Stage Left" on this small program... I am working out of "C - How to program"... Working as many Exercises from each Chapter... I understand the concept of using "Sentinel Values" to exit a program in which you dont know how many factors will be inPuted...

    I just can't seem to exit when I am asking the user for multiple inPuts.. I did find a simple "Sentinel Exit" and have been trying to work off it..... Please excuse sloppy errors... I am trying to build a fondation of programming and have found that pounding daily programs is what will make the difference in the End,,, < Which I hope will lead to a New Begenning!!!!!

    Any Hints or Help will be appreciated....


    #include "stdafx.h"

    #include <conio.h>


    int _tmain(int argc, _TCHAR* argv[])
    {
    /* Determine if customer has Exceeded Credit Limit */


    /* variables */

    int acctNum;
    // int cnter;

    double crdtBegBall ; /* Begenning Credit Ballance */

    double totChrges; /* Total Charges */
    double totCrdtd; /* Total Credit */
    double crdtLmt; /* Credit Limit */

    double totCrdtBall = 0; /* crdtBegBall + totCrdtd */



    /* processing phase - get input from User */

    printf("\nEnter Account Number (1- to end): ");
    scanf("%d", &acctNum); /* priming Read */

    printf("\nEnter Beggenning Credit Ballance: ");
    scanf("%d", &crdtBegBall);

    printf("\nEnter Total Charges: ");
    scanf("%d", &totChrges);

    printf("\nEnter Total Credit: ");
    scanf("%d", &totCrdtd);

    printf("\nEnter Credit Limit: ");
    scanf("%d", &crdtLmt);



    while (acctNum != -1)
    {

    totCrdtBall = crdtBegBall + totCrdtd;


    printf("\nEnter Account Number (1- to end): ");
    scanf("%d", &acctNum); /* Repeating Read */

    printf("\nEnter Beggenning Credit Ballance: ");
    scanf("%d", &crdtBegBall);

    printf("\nEnter Total Charges: ");
    scanf("%d", &totChrges);

    printf("\nEnter Total Credit: ");
    scanf("%d", &totCrdtd);

    printf("\nEnter Credit Limit: ");
    scanf("%d", &crdtLmt);

    }


    /* LOST TO AS WHERE TO PUT THIS */

    //if (totCrdtBall > crdtLmt)
    //{
    // printf("\nYou have Exceeded your Credit Limit");
    //}


    printf("\nThe Customer Account Number is: %d\n", acctNum);

    printf("\nThe Customer Credit Limit is: %d\n", crdtLmt);

    printf("\nThe Customer Credit Ballance is: %d\n", totCrdtd);



    getch();


    return 0;
    }
    Last edited by MAV_DevWantB; 09-08-2009 at 08:07 PM. Reason: did not finish...

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    No need to be desperate - post the code you're having trouble with. And please try to be coherent, as phrases like "Need to Exit Stage Left" and "Sentinel Exit" are only meaningful to *you* - the key here is clarity and specifics, above all.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You can make the while loop infinite (eg: while(1)), since the point where you want to decide when to exit is here:

    Code:
    printf("\nEnter Account Number (1- to end): ");
    scanf("%d", &acctNum); /* Repeating Read */
    /*
        Exit, if -1
    */
    EDIT:
    Oh, and put your code between tags, eg:

    [code]
    ...Code goes here...
    [/code]

    And try to indent your code, as well, eg:

    Code:
    while (x)
    {
          if (y)
          {
                foo();
          }
    }
    Last edited by Sebastiani; 09-08-2009 at 08:18 PM.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Location
    Aurora, CO
    Posts
    9
    Thanks for the Help, Sebastiani, I appreciate you taking the time to reply to my posting... I will take your advise going forward in Hopes of submitting future postings in a more meaningful manner.... You and your fellow programmers have much to share with future programmers like myself... Although I am new to all this I vow to NEVER submit a posting without putting several hours into compile & reserching my programs..... thnks

    I am submitting my working program and open to any more suggestion.... thnks All



    Code:
    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	/* Determine if customer has Exceeded Credit Limit */
    
    
    	/* initialize variables */
    	
    	int acctNum;
    	int cnter = 0;
    
    	float crdtBegBall = 0;               /* Begenning Credit Ballance */ 
    
    	float totChrges = 0;		/* Total Charges */
    	float totCrdtd = 0;		/* Total Credit */
    	float crdtLmt = 0;		/* Credit Limit */
    
    	float totCrdtBall = 0;	/* crdtBegBall + totCrdtd */
    
    	
    
    	/* processing phase - get input from User */
    
    	printf("\nEnter Account Number (1- to end): ");
    	scanf("%d", &acctNum);  /* priming Read */
    
    	
    
    	while (acctNum != -1)
    	{
    
    		if (acctNum != -1)
    		{
    
    		//printf("\nEnter Account Number (1- to end): ");
    		//scanf("%d", &acctNum);  /* priming Read */
    
    		printf("\nEnter Beggenning Credit Ballance: ");
    		scanf("%f", &crdtBegBall);
    
    		printf("\nEnter Total Charges: ");
    		scanf("%f", &totChrges);
    
    		printf("\nEnter Total Credit: ");
    		scanf("%f", &totCrdtd);
    
    		printf("\nEnter Credit Limit: ");
    		scanf("%f", &crdtLmt);	
    
    		
    		totCrdtBall = crdtBegBall + totCrdtd;
    
    		printf("\n=======================================\n");
    
    		printf("\nThe Customer Account Number:\t %d\n", acctNum);
    
    		printf("\nThe Customer Credit Limit:\t %.2f\n", crdtLmt);
    
    		printf("\nThe Customer Credit Ballance:\t %.2f\n", totCrdtBall);
    
    		printf("\n=======================================\n");
    
    
    		if (totCrdtBall > crdtLmt)
    		{
    			printf("\nYou have Exceeded your Credit Limit\n");
    			printf("\n================================\n");
    			printf("\n===============================\n\n");
    		}
    
    		else
    		{
    			acctNum = -1;
    		}
    
    		}
    
    		printf("\nEnter Account Number (1- to end): ");
    		scanf("%d", &acctNum);  /* priming Read */	
    	}
    
    	
    	return 0;
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So what is it exactly you want to do? If you want to check every piece of input to see if it's _SOMETHING_ and exit if that's the case, then do so. As it is now, you aren't checking every piece of input.


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

  6. #6
    Registered User
    Join Date
    Aug 2009
    Location
    Aurora, CO
    Posts
    9
    quzah'''' for now this is just a simple program verifying if the customer has max'd out on their Credit limit.... At this time there are no validations in place.... But that is coming is some of my other beginner programs....

    This is my first posting and "Sebastiani" was kind enough to mention to me to clearly state my intentions on these postings... So going forward I will work on that,,,, Thanks’’ all for your patients in reviewing my postings...

    I'm sure it is no surprise that you have a Rookie on board...... Once again thanks!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getexitcodeprocess exit code
    By rotis23 in forum Windows Programming
    Replies: 1
    Last Post: 09-23-2004, 06:09 AM
  2. Couple of Q's.....
    By oobootsy1 in forum C++ Programming
    Replies: 18
    Last Post: 02-23-2004, 02:03 PM
  3. Exit a function
    By MasterGBC in forum C Programming
    Replies: 3
    Last Post: 04-10-2003, 11:46 PM
  4. Am i using the exit() func correctly?
    By LonelyPlanderWa in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 03:29 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21