c - c中数字删除小数位的错误

标签 c console line rounding

我正在学习 C 语言初学者,当我运行代码时,它会丢失一些小数位。根据我手写的同类型方程,它应该等于 99.5 有人能告诉我我做错了什么吗?

#include <stdio.h>
//create the number variable
double number = 0;

//function prototypes
double get_input();
double get_next(double one, double two);
void print_result(void);
int main(){
  //get all the input needed
  double x_two = get_input();
  double x_one = get_input();
  //calculate third
  double x_three = get_next(x_one,x_two);
  //calculate fourth
  double x_four = get_next(x_three,x_two);
  //calulate fith and set to number
  number = get_next(x_four,x_three);
  //print the result
  print_result();
}
double get_input(void){
  double number = 0;
  //prompt the user for the information needed
  printf("Please enter a value > ");
  //take the user info and pass it back
  scanf("%lf",&number);
 return number;




}
double get_next(double minus_one, double minus_two){
  double number = (minus_two/2)+(3*minus_one);
  return number;

}

void print_result(void){

  printf("The result is: %lf",number);


}

方程如下给出 Xn = Xn−2/2 + (3 * xn-1)

我为 n-2 插入的数字是 2,n-3 是 3

最佳答案

您的 get_input() 需要返回一个值。 返回号码;

关于c - c中数字删除小数位的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28493133/

相关文章:

C 程序获取有效输入

android - Google Play 开发者统计 API

Java 循环通过命令行参数来查看用户输入的内容?

c:使用 scanf() 读取负数

python - 为什么这种 PyArray_SimpleNewFromData 段错误的简单用法?

python - Pycharm 2017.1 EAP Python 控制台和远程 Docker 解释器不能一起工作

javascript - 为什么 Firefox 开发者控制台引用的是 script.js?

c++ - 将一条线从2个点延长到一定长度

ios - 每行的 UITextView 边框

c - 在 Shell 脚本或 Perl 脚本中对单词进行排序,然后对包含数字和字符的句子进行排序