C++帮助,
#include
voidgetOption(int*option);
voidgetNumbers(int*option,float*number1,float*number2);
floatcalc(int*option,float*number1,float*number2);
voidprintResult(floatnumber1,floatnumber2,floatresult,intoption);
main()
{
floatoutcome;
floatnumber1,number2;
intoption;
do
{getOption(&option);
if(option=5)
{
getNumbers(&option,&number1,&number2);
outcome=calc(&option,&number1,&number2);
printResult(number1,number2,outcome,option);
}
}while(option!=5);
}
voidgetOption(int*option)
{
printf(":n");
scanf("%f",number1);
scanf("%f",number2);
if(*option==4&&*number2==0)
printf("除数不能为零!n");
}while(*option==4&&*number2==0);
}
floatcalc(int*option,float*number1,float*number2)
{
floatresult;
switch(*option)
{case1:result=*number1+*number2;break;
case2:result=*number1-*number2;break;
case3:result=*number1**number2;break;
case4:result=*number1/*number2;break;
}
returnresult;
}
voidprintResult(floatnumber1,floatnumber2,floatresult,intoption)
{
switch(option)
{
case1:printf("%.2f+%.2f=%.2fn",number1,number2,result);break;
case2:printf("%.2f-%.2f=%.2fn",number1,number2,result);break;
case3:printf("%.2f*%.2f=%.2fn",number1,number2,result);break;
case4:printf("%.2f/%.2f=%.2fn",number1,number2,result);break;
}
}