以非零状态退出

时间:2017-10-06 10:26:09

标签: c

我是编程新手,并尝试自己学习,我的代码中有错误,我不理解它的语法错误或我做错了。我使用了3具有它的条件的方程式并且用于指示,而do-while,if-else,with switch。在我引入变量a之后它向我显示错误"退出非零状态&#34 ;

#include <stdio.h>
#include <math.h>

int main() {
    float a,x,b;
    float L;
    int m;

    printf("Enter variables a,x,b:");
    scanf("%f%f%f,&a,&x,&b");
    printf("For using for instruction (enter 1)");
    printf("For using while instruction (enter 2)");
    printf("For using do-while instruction (enter 3)");
    printf("For using ef instruction (enter 4)");
    scanf("%d,&m");
    switch(m){
        case 1:
            for (x=0;x<1.2;x++)
            {
                L=2*cos(x-(3.14/6));
            }
            for (x=0;x>= 1.2 && x<=3.9;x++)
            {
                L=x*x/(a+cos(powf((x+b),3)));
            }
            for (x=0;x>3.9;x++)
            {
                L=fabs(x/2*a)+powf(sin(x+1),2);
            }
            break;
        case 2:
            while (x<1.2)
            {
                 L=2*cos(x-(3.14/6));
            }
            while (x>= 1.2 && x<=3.9)
            {
                 L=x*x/(a+cos(powf((x+b),3)));
            }
            while (x>3.9)
            {
                 L=fabs(x/2*a)+powf(sin(x+1),2);
            }
            break;
       case 3:
            do 
            {
                L=2*cos(x-(3.14/6));
            }
            while (x<1.2);
            do 
            {
                L=x*x/(a+cos(powf((x+b),3)));
            }
            while (x>= 1.2 && x<=3.9);
            do
            {
                L=fabs(x/2*a)+powf(sin(x+1),2);
            }
            while (x>3.9);
            break;
       case 4:
           if (x<1.2)
           {
               L=2*cos(x-(3.14/6));
           }
           else
           {
               printf("First statement is false");
           }
           if(x>= 1.2 && x<=3.9)
           {
               L=x*x/(a+cos(powf((x+b),3)));
           }
           else
           {
               printf("Second statement is false");
           }
           if(x>3.9)
           {
               L=fabs(x/2*a)+powf(sin(x+1),2);
           }
           else
           {
               printf("Third statement is false");
           }
           break;
       default:
           printf("\nNo right choices\n");
   }
   printf("Your answer is: L = %.3f,L");
}

3 个答案:

答案 0 :(得分:3)

您的问题是您的scanf参数格式不正确。

而不是scanf("%f%f%f,&a,&x,&b");使用scanf("%f%f%f",&a,&x,&b);。第二个scanf中的内容相同。

变量地址是参数,不是字符串的一部分。

当您致电时,scanf会找到第一个%f,但它没有任何地址可以将值存入。或者更准确地说,它从垃圾中找到它需要的值(读取有关堆栈和动态参数的数量),因为你没有插入它。

答案 1 :(得分:1)

scanf("%f%f%f,&a,&x,&b");应该像这样scanf("%f%f%f",&a,&x,&b);。请更正您使用scanf的位置。由于语法错误,您的代码未从用户那里获取输入。我已编译并尝试正确运行。请在每个地方更改scanf语法。

  1. scanf("%f%f%f,&a,&x,&b")scanf("%f%f%f",&a,&x,&b)
  2. scanf("%d,&m");scanf("%d",&m);
  3. printf("Your answer is: L = %.3f,L");printf("Your answer is: L = %.3f",L);

答案 2 :(得分:0)

你错过了返回0;声明在主要功能结束时。由于c main函数是 int main()

相关问题