#includevoid get_num(float a,float b);int main(void){char ch;float m,n,s;printf("Enter the operatioa of your choice:\n");printf("a.add b.subtract\n""c.multiply d.divide\n""q.quit\n");scanf("%c",&ch);while(ch!='q'){switch(ch){case 'a':get_num(m,n);s=m

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 15:48:25
#includevoidget_num(floata,floatb);intmain(void){charch;floatm,n,s;printf("Entertheoperatioaofyourch

#includevoid get_num(float a,float b);int main(void){char ch;float m,n,s;printf("Enter the operatioa of your choice:\n");printf("a.add b.subtract\n""c.multiply d.divide\n""q.quit\n");scanf("%c",&ch);while(ch!='q'){switch(ch){case 'a':get_num(m,n);s=m
#include
void get_num(float a,float b);
int main(void)
{
char ch;
float m,n,s;
printf("Enter the operatioa of your choice:\n");
printf("a.add b.subtract\n"
"c.multiply d.divide\n"
"q.quit\n");
scanf("%c",&ch);
while(ch!='q')
{
switch(ch)
{
case 'a':
get_num(m,n);
s=m+n;
printf("%f+%f=%f\n",m,n,s);
break;
case'b':
get_num(m,n);
s=m-n;
printf("%f-%f=%f\n",m,n,s);
break;
case'c':
get_num(m,n);
s=m*n;
printf("%f*%f=%f\n",m,n,s);
break;
case'd':
get_num(m,n);
s=m/n;
printf("%f/%f=%f\n",m,n,s);
break;
default:
printf("Input error!\n");
break;
}
}
printf("Bye.\n");
return 0;
}
void get_num(float a,float b)
{
printf("Enter first number:");
scanf("%f",&a);
printf("\nEnter second number:");
scanf("%f",&b);
if(a=0)
{
printf("Enter a number other than 0:");
scanf("%f",&a);
}
if(b=0)
{
printf("Enter a number other than 0:");
scanf("%f",&b);
}
if(scanf("%f",&a)!=1)
{
printf("%c is not an number.\n",a);
printf("Please enter a number,such as 10 ,22,2.9:");
scanf("%f",&a);
}
if(scanf("%f",&b)!=1)
{
printf("%c is not an number.\n",b);
printf("Please enter a number,such as 10 ,22,2.9:");
scanf("%f",&b);
}
}
输入第三个后开始就不行了.请问哪错了谢谢
额.回答时.如果能运行一下看看结果就更好了.能够讲的白点.

#includevoid get_num(float a,float b);int main(void){char ch;float m,n,s;printf("Enter the operatioa of your choice:\n");printf("a.add b.subtract\n""c.multiply d.divide\n""q.quit\n");scanf("%c",&ch);while(ch!='q'){switch(ch){case 'a':get_num(m,n);s=m
是用C进行,四则运算吧:
这里给你两个源码:
第一段程序:是我自己写的
第二段是完善了你的程序:
////////////////////第一段//////////////////////////
#include "stdio.h"
main()
{
float a,b;
int op;
while(1)
{
printf("Input a:");
scanf("%f",&a); //输入a
printf("Input b:");
scanf("%f",&b); //输入b
//-----输出提示信息----------
printf("Select Operator:\n");
printf("+ Input 1\n");
printf("- Input 2\n");
printf("* Input 3\n");
printf("\\ Input 4\n");
printf("Please Select:");
//-----输入操作符------------
scanf("%d",&op);
//-----对操作符进行判断------
switch(op)
{
case 1:// +
printf("a+b=%f\n",a+b);
break;
case 2:// -
printf("a-b=%f\n",a-b);
break;
case 3:// 乘
printf("a*b=%f\n",a*b);
break;
case 4:// 除
printf("a//b=%f\n",a/b);
break;
}
printf("\n");//再换一个行,以便下次输入
}
}
/////////////////第二段,完善你的程序/////////////////////
#include
#include
void get_num(float *a,float *b);
int main(void)
{
char ch;
float m,n,s;
while(ch!='q')
{
printf("Enter the operatioa of your choice:\n");
printf("-----------------------\n");
printf("a.add b.subtract\n");
printf("c.multiply d.divide\n");
printf("q.quit\n");
printf("-----------------------\n");
printf("Please Select:");
scanf("%c",&ch);
switch(ch)
{
case 'a':
get_num(&m,&n);
s=m+n;
printf("%f+%f=%f\n",m,n,s);
break;
case'b':
get_num(&m,&n);
s=m-n;
printf("%f-%f=%f\n",m,n,s);
break;
case'c':
get_num(&m,&n);
s=m*n;
printf("%f*%f=%f\n",m,n,s);
break;
case'd':
get_num(&m,&n);
s=m/n;
printf("%f/%f=%f\n",m,n,s);
break;
case 'q':
system("cls");
printf("Bye.\n");
return 0;
default:
printf("Input error!\n");
break;
}
system("pause");//暂停,以便看得数
system("cls"); //清屏
getchar();
}
return 0;
}
void get_num(float *a,float *b)
{
printf("Enter first number:");
scanf("%f",a);
printf("\nEnter second number:");
scanf("%f",b);
if(*a==0)
{
printf("Enter a number other than 0:");
scanf("%f",a);
}
if(*b==0)
{
printf("Enter a number other than 0:");
scanf("%f",b);
}
}