#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/06/16 16:09:32
![#includevoid get_num(float a,float b);int main(void){char ch;float m,n,s;printf(](/uploads/image/z/10822288-40-8.jpg?t=%23includevoid+get_num%28float+a%2Cfloat+b%29%3Bint+main%28void%29%7Bchar+ch%3Bfloat+m%2Cn%2Cs%3Bprintf%28%22Enter+the+operatioa+of+your+choice%3A%5Cn%22%29%3Bprintf%28%22a.add+b.subtract%5Cn%22%22c.multiply+d.divide%5Cn%22%22q.quit%5Cn%22%29%3Bscanf%28%22%25c%22%2C%26ch%29%3Bwhile%28ch%21%3D%27q%27%29%7Bswitch%28ch%29%7Bcase+%27a%27%3Aget_num%28m%2Cn%29%3Bs%3Dm)
#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);
}
}