为什么我得到-1。#R输出?

时间:2019-03-29 15:27:26

标签: c arrays printf scanf atom-editor

我正在尝试使用空格分隔的值来表示数组的销售额,当用户输入-1时,使用哨兵变量结束循环。打印循环将信息打印在表格中。但是,当我编译并运行程序时,输出结果为-1。#R。我为什么得到那个?

我正在使用Atom进行编写,并且使用tdm-gcc作为编译器。我已经知道,将sales声明为静态变量可以解决此问题。但是,为什么我得到了-1。#R输出?使用onlinegdb.com也可以解决此问题。我只是不明白-1。#R的意思。

static double sales[4][5];
  double sum=0, cache=0;
  int x=0,y=0;
  printf("Enter Salesperson Number (1-4), Product Number (1-5) and Total Product Value\n\n");
  while(x>=0) {
    scanf("%d",&x);
    if(x<0) break;
    scanf("%d%*c%lf", &y, &cache);
    sales[x-1][y-1] = cache;

  }

  printf("  %-13s%-18s%-18s%-18s%-18s%-18s\n", "","Salesperson 1","Salesperson 2","Salesperson 3","Salesperson 4","Total (Product)");
  for(int j=0;j<5;++j) {
    printf("  Product %-5d   ",j+1);
    for(int i=0; i<4; ++i) {
      printf("%-18.2f", sales[i][j]);
      sum += sales[i][j];
    }
    printf("%.2f\n",sum);
    sum=0;
  }
  printf("  Total           ");
  for(int i=0;i<4;++i) {
    sum=0;
    for(int j=0;j<5;++j) {
      sum += sales[i][j];
    }
    printf("%-18.2f", sum);
  }

1 2 10
-1
               Salesperson 1     Salesperson 2     Salesperson 3     Salesperson 4     Total (Product)
  Product 1       0.00              0.00              0.00              0.00              0.00
  Product 2       10.00             0.00              0.00              -1.#R             -1.#R
  Product 3       0.00              0.00              0.00              0.00              0.00
  Product 4       0.00              0.00              0.00              0.00              0.00
  Product 5       0.00              0.00              0.00              0.00              0.00
  Total           10.00             0.00              0.00              -1.#R

0 个答案:

没有答案
相关问题