- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该程序旨在接收 double 据类型值。然后使用自定义函数 get_double 验证数据类型,并使用相应函数和提供的值( double )获取面积/体积/周长。那里有一个 switch 语句,但我认为它不是导致问题的原因。
我真的不知道问题出在哪里。我尝试用两个不同的编译器进行编译,但仍然可以。
由于仅分享一小段代码,我认为不足以理解问题。我认为解决方案一定相当简单,但由于我是编程初学者,所以我看不到解决方案。
#include <stdio.h>
#include <ctype.h>
//OPTIONS
double volume (double radius, double height); //V = volume
double area (double radius); //A = area
double circumf (double radius); //C = circumference
//Q = quit
char get_option (void);
double get_double (void);
int main ()
{
int salir = 0;
char option;
double radius, area_answer, circumference_answer, height, volume_answer;
do {
// fflush(stdin);
//FFLUSH is important. It allows the buffer to be cleaned from the input entered when informing the program about the data needed (radius and height). Otherwise the DO WHILE loop is repeated additional and unnecerary times. IT CLEARS THE INPUT BUFFER!
//OPTION to FFLUSH. It can be used this loop after every scanf in the code: while ((getchar()) != '\n'); THIS LOOP CLEARS THE BUFFER!
printf("This program informs about he geometry of a circle (or a cylinder).\n");
printf("Choose an option:\n"
"\tA - Area\n\tC - Circumference\n\tV - Volume\n\tQ- Quit\n");
option = get_option ();
printf("\nThe selected option was: %c\n\n", option);
switch(option)
{
case 'a':
printf("Enter the radius of the circle (double type) to know its area:\n");
radius = get_double();
area_answer = area(radius);
printf ("The area of a circle with radius %f is: %f\n\n", radius, area_answer);
while ((getchar()) != '\n');
break;
case 'c':
printf("Enter the radius of the circle (double type) to know its circumference:\n");
radius = get_double();
circumference_answer = circumf(radius);
printf("The circumference of a circle with radius %f is: %f\n\n", radius, circumference_answer);
while ((getchar()) != '\n');
break;
case 'v':
printf("Enter the radius and height of the cylinder (double type) to know its volume:\n");
radius = get_double();
height = get_double();
volume_answer = volume (radius, height);
printf("The volume of a cylinder with radius %f and height %f is: %f\n\n", radius, height, volume_answer);
while ((getchar()) != '\n');
break;
case 'q':
salir = 1;
printf("You have quitted the program.\n");
break;
default:
printf("Uknown option. Please, try again.\n\n");
while ((getchar()) != '\n');
break;
}
} while (salir == 0);
return 0;
}
//FUNCTIONS
double volume (double radius, double height)
{
double volume, PHI = 3.14;
volume = PHI * radius * radius * height;
return volume;
}
double area (double radius)
{
double area = 0.0, PHI = 3.14;
area = PHI * radius * radius;
printf("PHI = %f\n", PHI);
printf("radius = %f\n", radius);
printf("area = %f\n\n", area);
return area;
}
double circumf (double radius)
{
double circumf, PHI = 3.14;
circumf = 2.0 * PHI * radius;
return circumf;
}
//GETTING CHAR OR DOUBLE
char get_option (void) // <------------------ this function is problematic
{
char input_char;
printf("> ");
input_char = getchar();
input_char = tolower (input_char);
return input_char;
}
double get_double (void)
{
double input_double;
while ((scanf("%lf", &input_double) != 1))
{
while (getchar() != '\n')
printf("> ");
}
printf("input_double = %f\n\n", input_double);
}
我认为问题可能出在函数 get_double
中的某个地方,但我不确定。我尝试了不同的方法来解决这个问题,但没有成功。
最佳答案
您忘记在函数末尾写入 return input_double;
double get_double (void)
...因此该函数返回垃圾,因为您没有返回任何值.
尝试一下,看看是否有效。
关于c - 从函数传递双值时无法打印答案(C 语言),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48832402/
(function() { main(); function main() { jQuery(document).ready(function($) {
所以我必须为我们的类(class)软件设计制作一个 GUI,我们正在为 children 制作一个游戏来练习乘法表。到目前为止,当您执行一次测试或练习时它工作正常,但是当您进行第二次运行时,它会出错。
我刚开始学习 python,想做一些琐事。基本上,我想从列表中随机询问一个问题,然后使用“输入”运算符来判断用户输入的 Y/N 是否正确。我坚持确定如何检查它是否正确。也许我的(不正确的)代码可以更好
我目前正在做一个暑期实习项目,我必须制作一个不经意的 DNS 翻译服务器。我不会在这里详细讨论被忽视的部分,但我会解释我的程序的架构。 有一个服务器端接收混淆的请求并发回一个它自己无法理解的答案。 在
我想用ajax请求翻译单词到谷歌翻译 如果我使用 curl,它会像: curl_init("http://translate.google.com/translate_a/t?client=t&tex
这是我运行dig www.google.com时的答案部分: ;; ANSWER SECTION: www.google.com. 108 IN A 74
我在ES上有以下简单数据: curl -XPUT localhost:9200/dt/art/1 -d '{ "age": 77 }' curl -XPUT localhost:9200/dt/art
我从编码开始,我有一个多维数组的示例。但它没有给出预期的答案。 我只得到“C”,我期待“JohnnyCash:Live at Folsom Prison”。出了什么问题? var music = []
我们有一个应用程序与 Crashlytic 和 Answers 配合得很好。我们需要为这个应用程序做一个不同的风格。因此,我们的 Gradle 编译工作正常,并为两个不同的品牌制作了两个不同的 APK
我正在尝试从数据库获取歌曲列表。 我在查询行中发送一个 ID 数组(永久链接),并且我希望返回值的顺序与我在数组中给出的顺序相同。有没有办法做到这一点? function getByPermalink
我有一个表单可以输入这样的值 test 有没有办法用jquery改变输入类型 我基本上想把这个添加到输入类型中 data-slider="true" data-sl
好吧,我距离数学高手还很远。哎呀,我记住了足够多的高中代数,可以拼凑出任何有效的公式,这对我来说是一个胜利。因此,如果您注意到这里有一个不必要的长或令人困惑的公式,那就可以解释了。 但是,正如人们可以
所以我的问题有点令人困惑,但仍然如此。我从外部源获取一个由 8 个字符串组成的数组,其中所有字符串都包含 double 值。这些值通常为小数点后 4 位: 12345.5678 我想做的是将其转换为小
我成功地构建了一个函数来提示用户提出问题,然后是随机排列的答案选项。但是,由于答案选择现在是随机的,python 如何识别用户输入(数字:1、2、3 或 4)以获得“正确”答案? import ran
我正在尝试使用蛮力来回答这个问题,这样我就可以理解发生了什么: https://www.interviewcake.com/question/java/product-of-other-numbers
尝试使用刚刚宣布的 Answers OSX平台框架: pod 'Fabric' pod 'Answers' pod 'Crashlytics' #import #import #import [
在我添加的页面上检索忘记的用户名 步骤 1) 输入电子邮件地址(通过电子邮件获取帐户) 第 2 步)验证安全问题(他们提供答案,我对其进行验证) 第 3 步)向他们发送带有用户名的电子邮件 第 2 步
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
在我的测试中,我需要模拟一种情况,当使用实体管理器(em)将新对象保存到数据库中时,在此过程中,该对象的id属性设置为数据库中该行的自动递增ID。我想将该id属性设置为我自己的值,以便稍后在测试中进行
我有这个代码。调用askToContinue() 方法来询问用户是否要继续,但我的问题是它只是忽略选择并重新启动程序,无论我输入什么。我在代码中遗漏了什么导致它忽略我的选择? public class
我是一名优秀的程序员,十分优秀!