为什么我不能在这个编码中绘制图表? [英] Why I can't plot a graph in this coding?

查看:74
本文介绍了为什么我不能在这个编码中绘制图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <math.h>
#include <chplot.h>
#define N 10         /*for 5 step size*/
#define A 10.0      /*constant value of shear stress in kgf/mm^2*/


double calculate_thickness(double r);

int main(){
    
    int  x0=100,xf=500,xstep=50;  
    double i,j,r,w,E;
    double P[N],t[N];

    printf("Enter the value of plate width, w in mm: ");      /*plate width in mm*/
    scanf("%lf",&w);
    
    printf("*Enter 1 for radiography inspection\n");         /*selection of inspection*/
    printf("*Enter 2 for no radiography inspection\n");
    printf("Enter your type of inspection: ");
    scanf("%lf",&r);
    
    printf("  Tensile load,P(kN)   |    thickness,t(mm) \n");   /*for table uses*/
    printf("--------------------------------------------\n");
   
    if(r == 1){
        E=0.9;  /*efficiency when radiography inspection 90%*/
        for (i=0; i<n;>            P[i]=x0+i*xstep;
            t[i]=P[i]/(w*(E*A));    /*equation to find the thickness of welding specimen*/
            printf("     %6.f            |     %6.3f     \n",P[i],t[i]);
        }
    }
    else if(r ==2){
        E=0.65;  /*efficiency when no radiography inspection 65%*/
        for (j=0; j<n;>            P[j]=x0+j*xstep;
            t[j]=P[j]/(w*(E*A));    /*equation to find the thickness of welding specimen*/
            printf("     %6.f            |     %6.3f     \n",P[j],t[j]);
        }
    }
    else{
        printf("Error!\n");
    }
    return 0;
}
double calculate_thickness(double r)
{
    int i,j,r;
    double t[N],P[N];
    
    if (r == 1){
        scanf("%lf",&P[i]);
        scanf("%lf",&t[i]);
    }
    else if (r == 2){
        scanf("%lf",&P[j]);
        scanf("%lf",&t[j]);
    }
    else{
        printf("Error!");
    }
    plotxy(P, t, N, "Acceleration Plot","Tensile load(kN)", "thickness(mm)");
    return 0;
}





我的尝试:



我已经尝试使用另一个函数并检查我在数组规则中学到了什么。我不知道为什么图表没有出来。错误说ERROR:计算数组类型限定符应用于标量变量

错误:函数不能返回C数组,它只能返回计算数组



What I have tried:

I already try to used another function and check the note what I have learn in array rules. I have no idea why the graph is not come out. The error said that "ERROR: computational array type qualifier applied to a scalar variable
ERROR: function cannot return C array, it can only return computational array"

推荐答案

起初最重要的是

At first and most important
double calculate_thickness(double r) // here comes an r
{
    int i,j,r; //here is the OTHER r !!!!!
    double t[N],P[N];
    
    if (r == 1){





你对the plotxy的召唤完全是错误的。你必须初始化数组的所有N字段,例如





Your call of the plotxy is totally buggy. You must initialize ALL N-fields of the array like

double t[N] = {0};

并根据需要调整N.



提示:学习使用调试器并在控制台上输出!!!

and make N as little as needed.

Tip: Learn to use the debugger and make outputs on the console!!!


我担心你没有调用例程 calculate_thickness 那个情节可能是你的问题之一。

使用未初始化的变量也无济于事。

在情节中仅定义1点例程也可能是个问题。
I fear that the fact that you don't call the routine calculate_thickness that do the plot can be one of your problems.
Using uninitialized variables will not help either.
defining only 1 point in the plot routine may also be a problem.


这篇关于为什么我不能在这个编码中绘制图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆