【发布时间】:2021-11-06 15:49:23
【问题描述】:
我已经编写了一些关于 uni 赋值的代码,但我一直遇到这样的问题,即我的自定义函数没有提供任何其他输出然后为零。
基本上,我是在询问如何检索要在我的代码中使用的函数的结果。
在这里我将粘贴我的代码。
#include <stdio.h>
//math.h is included via the header file because the compiler liked it better.
int V;
int H;
int R;
int result;
#include "A1_header.h"
int main()
{
//small introduction
printf("Welcome to the volume test game\n");
printf("We will start with spheres. \n");
printf("Please input your sphere radius here:");
scanf("%d", &R);
CalcSphVolume(&V, &R);
printf("please input your result:");
scanf("%d", &result);
if(result == V){
printf("Congratulations, your answer is correct!\n");
}
else{
printf("Wrong answer, the correct result was %d \n", V);
}
return 0;
}
下面是我用来定义函数的 .h 文件。
#ifndef Point
#define Point
#include <math.h>
//these are the functions for Sphere calculations
void CalcSphVolume(int V, int R) {
V = 1.33*3.14(R*R*R);
}
void CalcSphRadius(int V, int R) {
R = cbrt(V/4.1762);
return;
}
//these are the functions for the Cone calculations
void CalcConVolume(int V, int R, int H) {
V = 0.33*(3.14*(R*R))H;
return;
}
void CalcConHeight(int V, int R, int H) {
H = V/(0.33*(3.14*(R*R)));
}
void CalcConRadius(int V, int R, int H) {
R = sqrt(V/(0.33*3.14H));
}
//these are the functions for the Cilinder calculations
void CalcCilVolume(int V, int R, int H) {
V = 3.14*H*(R*R);
}
void CalcCilHeight(int V, int R, int H) {
H = V/(3.14(R*R));
}
void CalcCilRadius(int V, int R, int H) {
R = sqrt(V/(3.14*H));
}
#endif
【问题讨论】:
-
您的标题中缺少
#endif,这也可能是当您在标题中包含math.h时“编译器更喜欢它”的原因。
标签: c shared-libraries