spadewarrior
June 3rd, 2008, 03:36 PM
Could one of you fine people please look at this function I've written and show me where the segmentation fault is? I've been staring at it for about 30 minutes and cannot work it out. It's driving me mad. i'm sure it's obvious but I've been working on this so long I must be going blind.
Help appreciated.
int get_money(void)
{
int total, coin;
system("clear");
mvprintw(12, 22, "Please enter money. ");
mvprintw(13, 22, "Only 5p, 10, 20p, 50p or 100p accepted. ");
mvprintw(14, 22 ,"Enter 0 to finish ");
refresh();
while(coin!=0)
{
fflush(stdin);
scanf("%d", coin);
if( (coin==5) || (coin==10) || (coin==20) || (coin==50) || (coin==100) )
{
total=(total+coin);
}
else
{
mvprintw(16, 22, "Invalid coin ");
refresh();
}
}
return total;
}
Help appreciated.
int get_money(void)
{
int total, coin;
system("clear");
mvprintw(12, 22, "Please enter money. ");
mvprintw(13, 22, "Only 5p, 10, 20p, 50p or 100p accepted. ");
mvprintw(14, 22 ,"Enter 0 to finish ");
refresh();
while(coin!=0)
{
fflush(stdin);
scanf("%d", coin);
if( (coin==5) || (coin==10) || (coin==20) || (coin==50) || (coin==100) )
{
total=(total+coin);
}
else
{
mvprintw(16, 22, "Invalid coin ");
refresh();
}
}
return total;
}