这是我第一次发帖,所以我无法将代码直接发到文本框中。
我遇到的问题是它自动生成数字而不是提示用户输入。我是 C 的新手,所以我不太明白我做错了什么。提前致谢。
#include <stdio.h>
#include <stdlib.h>
//function prototype
int getLength();
int getWidth();
int getHeight();
int vol (int, int, int);
int sA(int, int, int);
void disp(int, int);
int main()
{
//declarations
int a = 0;
int b = 0;
int c = 0;
int volume = 0;
int surfaceArea = 0;
//input
//calculation
volume = vol(a, b, c);
surfaceArea = sA(a, b, c);
a = getLength;
b = getWidth;
c = getHeight;
//output
disp(vol,surfaceArea);
return 0;
}//end main
//get length
int getLength()
{
int length = 0;
printf("enter length: ");
scanf("%d", &length);
return length;
}
//get width
int getWidth()
{
int width = 0;
printf("enter width: ");
scanf("%d", &width);
return width;
}
int getHeight()
{
int height = 0;
printf("enter height: ");
scanf("%d", &height);
return height;
}
int vol(length, width, height)
{
//return a * b * c
int volume = 0;
volume = (length * width * height);
return volume;
}//end volume
int sA(length, height, width)
{
//declare variables
int wL1 = 0;
int wL2 = 0;
int wL3 = 0;
int surfaceArea = 0;
//breaking up into small portions
wL1 = (width*length);
wL2 = (height*length);
wL3 = (height*width);
surfaceArea = 2*(wL1+wL2+wL3);
//return A=2(wl+hl+hw)
return surfaceArea;
}//end surface area
void disp(volume,surfaceArea)
{
//display results
printf("The Volume of the Rectangular Prism is: %d \n\n", volume );
printf("The Surface Area of the Rectangular prism is: %d", surfaceArea);
}
最佳答案
我想你想改变这个:
//Line 18
volume = vol(a, b, c);
surfaceArea = sA(a, b, c);
a = getLength;
b = getWidth;
c = getHeight;
//Line 33
disp(vol,surfaceArea);
//Line 64
int vol(length, width, height)
//Line 73
int sA(length, height, width)
//Line 91
void disp(volume, surfaceArea)
为此:
//Line 18
a = getLength();
//^^Call the function and assign the value before you call functions with this variable
b = getWidth();
c = getHeight();
volume = vol(a, b, c);
surfaceArea = sA(a, b, c);
//Line 33
disp(volume, surfaceArea);
//^^^^^^ vol doesn't exists i think you wanted to use volume
//Line 64
int vol(int length, int width, int height)
//^^^ Declare the type of the variable, like in your prototype
//Line 73
int sA(int length, int height, int width)
//Line 91
void disp(int volume,int surfaceArea)
关于c - 我似乎无法让我的 C 程序接受输入(直角棱柱计算器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27994911/