关于c编计算器的循环问题

来源:百度知道 编辑:UC知道 时间:2024/04/30 02:20:03
这是我的程序:
#include<stdio.h>
#include<conio.h>
void main()
{float a,b;
char c;
gotoxy(1,3);
printf("***********************\n");
printf("* *\n");
printf("* *\n");
printf("***********************\n");
printf("* 7 8 9 * - *\n");
printf("* 4 5 6 * + *\n");
printf("* 1 2 3 * / *\n");
printf("* 0 . * * *\n");
printf("***********************\n");
gotoxy(2,4);
scanf("%f%c%f",&a,&c,&b);
switch(c)
{case'+':gotoxy(5,4);printf("=%f\n",a+b);break;
case'-':gotoxy(5,4);printf("=%f\n",a-b);break;
case'*':gotoxy(5,4);printf("=%f\n",a*b);break;
case'/':gotoxy(5,4);printf(

加个while就可以了。顺便有几处可以简写的也帮你改了下。代码如下。

#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
char c, cmd = 'y';
while(cmd == 'y')
{
gotoxy(1,3);
printf("***********************\n");
printf("* *\n");
printf("* *\n");
printf("***********************\n");
printf("* 7 8 9 * - *\n");
printf("* 4 5 6 * + *\n");
printf("* 1 2 3 * / *\n");
printf("* 0 . * * *\n");
printf("***********************\n");

gotoxy(2,4);
scanf("%f%c%f",&a,&c,&b);
gotoxy(5,4);
switch(c)
{
case'+':printf("=%f\n",a+b);break;
case'-&#