C语言程序如何从下层返回到上层


#define _CRT_SECURE_NO_WARNINGS
#define PI 3.1415926535
#include <stdio.h>
#include <math.h>
int main()
{
    double ito;
    double res;
    char a[10];
    while (1>0)
    {
        scanf("%lf", &ito);
        if (ito <= 1)
        {
            res = acos(ito) * 180 / PI;
            printf("out=%lf\n", res);
        }
        else
        {
            printf("wrong\n");
            scanf("%s", a);
            if (a == 'STOP')    return 0;
            else return;
        }
    }
}

程序第23行:我希望做到当输入字符串不是‘STOP'时,程序能够返回至第12行运行

你的判断语句不对,返回12行,也就是继续下一次循环,你什么也不需要做就自动会进行下一次循环了
最后判断代码改成如下即可:(开头增加#include <string.h>)

if (strcmp(a,"STOP") == 0)   
     return 0;
      

可以goto,但不推荐goto
可以了解一下C语言的continue关键字,会跳出当前循环直接进行下一次循环
有帮助望采纳

吧else return删了试一下

修改如下,供参考:

#define _CRT_SECURE_NO_WARNINGS
#define PI 3.1415926535
#include <stdio.h>
#include <math.h>
#include<string.h>
int main()
{
    double ito;
    double res;
    char a[10];
    while (1)//while (1 > 0)
    {
        printf("Input a number:\n");
        scanf("%lf", &ito);
        if (ito <= 1)
        {
            res = acos(ito) * 180 / PI;
            printf("out=%lf\n", res);
        }
        else
        {
            printf("wrong!\n");
        }
        printf("Input again or Quit(‘Y’ or 'STOP'):\n");
        scanf("%s", a);
        //if (a == 'STOP')    return 0;
        if (strcmp(a, "STOP") == 0) return 0;
        //else  return;
        
    }
}