字典翻译 问答 其它 【C++帮助,#includevoidgetOption(int*option);voidgetNumbers(int*option,float*number1,float*number2);floatcalc(int*option,float*number1,float*number2);voidprintResult(floatnumber1,floatnumber2,floatresult,intoption);main(){floatoutcome;】
问题标题:
【C++帮助,#includevoidgetOption(int*option);voidgetNumbers(int*option,float*number1,float*number2);floatcalc(int*option,float*number1,float*number2);voidprintResult(floatnumber1,floatnumber2,floatresult,intoption);main(){floatoutcome;】
问题描述:

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;

}

}

潘树陆回答:
  #include//:n");scanf("%f",number1);scanf("%f",number2);if(*option==4&&*number2==0)//意思为option为4(除号),并除数为0,不能计算printf("除数不能为零!n");}while(*option==4&&*number2==0);//直到...
点击显示
其它推荐
热门其它推荐
  • 其它