help with repeatedly calling the user

This is a discussion on help with repeatedly calling the user within the C Programming forums, part of the General Programming Boards category; Ok so here it is, The programs basic function is to calculate the estimated annual income of fast food industries ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    23

    Question help with repeatedly calling the user

    Ok so here it is, The programs basic function is to calculate the estimated annual income of fast food industries after 2005 (any year, the user wants), i have all that done. however the program wants me to have it repeatedly ask the user to input, and this is giving me the hardest time how would i get the program to repeatedly call the function and stop
    , any help would be gladley appreciated.
    Code:
    #include <stdio.h>
    #include <math.h>
    
    int
    main(void)
    
    {
            /* variables */
        int t; /* amount of years between 2005 and the input year */
        double F; /* formula for estimated annual income for fast food */
        int year; /* year inputed by user */
        int status; /* status value returned by user */
        int error; /* error flag for bad input */
        int skip_int; /* Skips the integer */
         
            
                
                printf(" Please put any year after 2005 to estimate the annual income of fast food, note if any year is entered before 2005 this program will display an error and end the program");
                scanf("%d", &year);
                
                    if (year < 2005 ) 
                        {
                            printf("Invalid year program ending >>%d>>.", year);
                            
                        }
                    else if ( year >= 2005 )
                         {
                              t = year - 2005;
                              F = 33.2 + (16.8 * t); 
                              
                              printf("The estimated annual income in %d is expected to be %.2f Billion\n", year, F);
                         }
    
                          system("pause");
                return (0);
                
    }
    Last edited by AlexTank853; 09-29-2012 at 09:56 PM.

  2. #2
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    You need an infinite loop ... and a way to get out of it -- so it isn't really infinite

    You can use any of the 3 loop constructs (I prefer the while)

    Code:
    while (1) {
        /* infinite stuff */
        if (leave_loop) break;
        /* infinite stuff */
    }
    Code:
    for (;;) {
        /* infinite stuff */
        if (leave_loop) break;
        /* infinite stuff */
    }
    Code:
    do {
        /* infinite stuff */
        if (leave_loop) break;
        /* infinite stuff */
    } while (1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rand() function giving same number repeatedly
    By Adam_H in forum C Programming
    Replies: 2
    Last Post: 11-15-2009, 08:43 AM
  2. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  3. To call a function repeatedly after certain period
    By babu198649 in forum C++ Programming
    Replies: 23
    Last Post: 07-15-2008, 08:21 AM
  4. save repeatedly entered info
    By dpacinator in forum C++ Programming
    Replies: 2
    Last Post: 08-18-2003, 07:54 PM
  5. Calling a user-defined function in C++
    By brianptodd in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2002, 12:09 PM

Tags for this Thread


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