problem with fscan

Discussion in 'C Programming' started by Morris Dovey, Feb 28, 2008.

  1. Morris Dovey

    Morris Dovey Guest

    orrgal wrote:
    >
    > in trying to run the code below i get an infinite loop. i thought the
    > code was supposed to stop at the scanf command each time it gets there
    > but apparently it just keeps going. what is the solution to this?


    You might care to notice that your input stream contains a
    newline.

    --
    Morris Dovey
    DeSoto Solar
    DeSoto, Iowa USA
    http://www.iedu.com/DeSoto
    Morris Dovey, Feb 28, 2008
    #1
    1. Advertising

  2. Morris Dovey

    orrgal Guest

    in trying to run the code below i get an infinite loop. i thought the
    code was supposed to stop at the scanf command each time it gets there
    but apparently it just keeps going. what is the solution to this?
    thanks.


    #include <stdio.h>
    #include <stdlib.h>


    /
    *=========================================================================
    Constants and definitions:
    ==========================================================================*/
    #define PERIOD 6;
    #define MAX_PCT 14;
    #define DISCOUNT 15;

    /
    *=========================================================================
    Functions:
    ==========================================================================*/
    //Returns smaller of two doubles
    double mindbl(double a,double b)
    {
    return a<b?a:b;
    }

    /
    *-------------------------------------------------------------------------
    The main program. Calculates share investment and profit.

    -------------------------------------------------------------------------
    */
    int main()
    {



    int pct,salary,scanres,dscnt,prd,maxpct;
    double beginprc,endprc,invest,dscntprc,cost,income,stocks,profit;
    dscnt=DISCOUNT;
    prd=PERIOD;
    maxpct=MAX_PCT;

    //read salary
    scanres=0;
    while(scanres!=1)
    {
    printf("\nEnter salary:");
    scanres=scanf("%d",&salary);
    if(scanres==1)
    {
    scanres= salary>0?1:0;
    }
    if(scanres==0) printf("\nInvalid input");
    }

    }
    orrgal, Feb 28, 2008
    #2
    1. Advertising

  3. Morris Dovey

    Mark Bluemel Guest

    orrgal wrote:


    [(S)He's having trouble with scanf for interactive input]

    have you looked at the FAQ at http://www.c-faq.com ? Question 12.20 is
    probably relevant :) Question 12.19 addresses your current issue.
    Mark Bluemel, Feb 28, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    3,954
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,141
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    1,947
    Merek
    Dec 3, 2003
  4. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    535
    Bullschmidt
    May 11, 2004
  5. Pasquale Frega

    fscan: about it

    Pasquale Frega, Nov 4, 2011, in forum: C Programming
    Replies:
    8
    Views:
    396
    Keith Thompson
    Nov 5, 2011
Loading...

Share This Page