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,scan res,dscnt,prd,m axpct;
double beginprc,endprc ,invest,dscntpr c,cost,income,s tocks,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("\nInval id input");
}
}
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,scan res,dscnt,prd,m axpct;
double beginprc,endprc ,invest,dscntpr c,cost,income,s tocks,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("\nInval id input");
}
}
Comment