/*************************************************************************
*
* bbs 小程式集 by Ptt
*
*************************************************************************/
#include "bbs.h"
/* 使用錢的函數 */
int
inmoney(int money)
{
cuser.money += money;
substitute_record(fn_passwd, &cuser, sizeof(userec), usernum);
return cuser.money;
}
int
demoney(int money)
{
if((unsigned long int)cuser.money <=
(unsigned long int) money) cuser.money=0;
else cuser.money -= money;
substitute_record(fn_passwd, &cuser, sizeof(userec), usernum);
return cuser.money;
}
/* 小計算機 */
void
ccount(float *a,float b,int cmode)
{
switch(cmode)
{
case 0:
case 1:
case 2:
*a += b;
break;
case 3:
*a -= b;
break;
case 4:
*a *= b;
break;
case 5:
*a /= b;
break;
}
}
int
cal()
{
float a=0;
char flo=0,ch;
char mode[6] = {' ','=','+','-','*','/'} , cmode=0;
char buf[100]= "[ 0] [ ] ",b[20]="0";
move(b_lines - 1, 0);
clrtoeol();
outs(buf);
move(b_lines, 0);
clrtoeol();
outs(" 小計算機 (0123456789+-*/=) 輸入 (Q) 離開 ");
while(1)
{
ch = igetch();
switch(ch)
{
case '\r':
ch = '=';
case '=':
case '+':
case '-':
case '*':
case '/':
ccount(&a,atof(b),cmode);
flo =0;
b[0]='0';
b[1]=0;
move(b_lines - 1, 0);
sprintf(buf,"[%13.2f] [%c] ",a,ch);
outs(buf);
break;
case '.':
if(!flo) flo =1;
else break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
if(strlen(b)>13) break;
if(flo || b[0]!='0')
{
sprintf(b,"%s%c",b,ch);
}
else
{
b[0]=ch;
}
move(b_lines - 1, 0);
sprintf(buf,"[%13s] [%c]",b,mode[cmode]);
outs(buf);
break;
case 'q':
return;
}
switch(ch)
{
case '=':
a=0;
cmode=0;
break;
case '+':
cmode = 2;
break;
case '-':
cmode = 3;
break;
case '*':
cmode = 4;
break;
case '/':
cmode = 5;
break;
}
}
}