问题描述
#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"
推荐答案
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!!!
这篇关于为什么我不能在这个编码中绘制图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!