Loop help

This is a discussion on Loop help within the C Programming forums, part of the General Programming Boards category; I need help with this, the loop does not seem to stop and I added a breakpoint but got an ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    47

    Loop help

    I need help with this, the loop does not seem to stop and I added a breakpoint but got an error. Have to sum all of the dep and then sum all with, then get a finbal.

    Any help would be grateful.


    Code:
    /*Checkbook Reconciliation Program*/
    
    #include <stdio.h>
    
    #define SENTINEL 0
    
    float endbal,
    	  finbal;
    
    int main (void)
    {
    	int   outdep = 0,
    		  withdraw = 0;
    
    
    printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
    scanf ("%d", & outdep);
    while (outdep!= SENTINEL)
    	{
    		finbal += outdep;
    		printf("Enter outstanding dep (%d to quit)>", SENTINEL);
    		scanf("%d", & outdep);
    	}
    
    printf("Outstanding check/withdrawal (or %d to quit)>", SENTINEL);
    scanf ("%d", & withdraw);
    while (withdraw!=SENTINEL)
    	{
    		finbal += withdraw;
    		printf("Enter withdrawal (%d to quit)>", SENTINEL);
    		scanf("%d", & withdraw);
    	}
    
    	finbal = endbal + outdep - withdraw;
    
    	printf("Your final balance in your checkbook should be $ %f\n", finbal);
    
    	return 0;
    
      }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can't read in a number with a decimal point using %d.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    Actually, I just changed this and now it stops at the top when you enter a date for program. I am not sure what is wrong, braces missing?

    Code:
    #include <stdio.h>
    
    #define SENTINEL 0
    
    float endbal,
    	  finbal;
    int   date;
    
    int main (void)
    {
    	int   outdep = 0,
    		  withdraw = 0;
    
    /*CHECKBOOK RECONCILIATION PROGRAM*/
    /*================================*/
    
    /*This program will help you to reconcile your checkbook.*/
    /*Be sure that your printer is ready for use.*/
    
    /*What is today's date (MN/DY.YR)?*/
    printf ("CHECKBOOK RECONCILIATION FOR:");
    scanf ("%d",date);
    
    printf("n\n");
    
    /*What was the ending balance on your last statement?*/
    printf ("Ending balance on last bank statement:");
    scanf ("%f", & endbal);
    
    /*Enter below any deposits recorded in your checkbook which*/
    /*do not appear on your bank statement.  Enter 0 when done.*/
    
    printf("Enter Outstanding dep (or %d when done)>", SENTINEL);
    scanf ("%d", & outdep);
    while (outdep!= SENTINEL)
    	{
    		finbal += outdep;
    		printf("Enter Outstanding deposits (%d when done)>\n\n", SENTINEL);
    		scanf("%d", & outdep);
    	}
    
    /*Enter below any check/witdrawals recorded in your*/
    /*checkbook which do not appear on your bank statement.*/
    /*Enter 0 when done.*/
    
    
    
    
    printf("Outstanding check/withdrawal (or %d when done)>", SENTINEL);
    scanf ("%d", & withdraw);
    while (withdraw!=SENTINEL)
    	{
    		finbal += withdraw;
    		printf("Outstanding check/withdrawals: (%d when done)>", SENTINEL);
    		scanf("%d", & withdraw);
    	}
    
    	finbal = endbal + outdep - withdraw;
    
    	printf("Your final balance in your checkbook should be $ %f\n", finbal);
    
    	return 0;
    
      }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Compile with warnings on. scanf expects pointers. You need the & operator on your date.


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

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    A date is not a number, so your scanf() will fail, even with a proper ampersand added.

    The operating system will give you the date you need. If you want to get the date from the user, you need to use a string of char's (best), or have the date entered as a valid number, like, after some good prompts by your program:

    Month: 10
    Day: 1
    Year: 2009


    Note that 01 is not a valid number.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    01 is a valid number, if you like Octal.


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

  7. #7
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by quzah View Post
    01 is a valid number, if you like Octal.


    Quzah.
    and you can read it just fine with %i (never use %d, will it read all formats too?)

  8. #8
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    I changed that and now it states that I am missing a prototype. can you tell me what that is. I am using Lcc compiler

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    i changed this is all works except now it will not give me the correct total for finbal.

    This is what I have:

    Code:
    #include <stdio.h>
    
    #define SENTINEL 0
    
    float endbal,
    	  finbal;
    
    int main (void)
    {
    	int   outdep = 0,
    		  withdraw = 0;
    
    		  printf("Ending balance on statement:");
    		  scanf ("%f", & endbal);
    
    printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
    scanf ("%d", & outdep);
    while (outdep!= SENTINEL)
    	{
    		finbal += outdep;
    		printf("Enter outstanding dep (%d to quit)>", SENTINEL);
    		scanf("%f", & outdep);
    	}
    
    printf("Outstanding check/withdrawal (or %d to quit)>", SENTINEL);
    scanf ("%d", & withdraw);
    while (withdraw!=SENTINEL)
    	{
    		finbal += withdraw;
    		printf("Enter withdrawal (%d to quit)>", SENTINEL);
    		scanf("%f", & withdraw);
    	}
    
    	finbal = endbal + outdep - withdraw;
    
    	printf("Your final balance in your checkbook should be $ %f\n" , finbal);
    
    	return 0;

  10. #10
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    > int outdep = 0,
    > withdraw = 0;
    ...

    > printf("Enter outstanding dep (%d to quit)>", SENTINEL);
    > scanf("%f", & outdep);

  11. #11
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    I changed that but I cannot seem to get this to calculate the final balance, it gets the beg bal, out dep and with, but will not calculate.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Post your latest attempt. Making us guess at what you have or have not changed doesn't help anyone.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poll event loop
    By rogster001 in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2009, 04:28 AM
  2. need help with a loop
    By Darkw1sh in forum C Programming
    Replies: 19
    Last Post: 09-13-2009, 09:46 PM
  3. funny-looking while loop
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2009, 11:54 PM
  4. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

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