【发布时间】:2014-02-26 12:14:29
【问题描述】:
我正在学习 C,并在教程中找到了这段代码,它工作正常,但如果我尝试生成一个十进制数(如 5.5),它会在以下数组中打印一个负数并自行循环。
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <math.h>
#include "stdafx.h"
#define ARBEITER 3
#define TAGE 5
#define ARBEITSKALENDER kalender();
int zeitkonto[ARBEITER][TAGE];
/* Fehlerausgabe */
void error(int n) {
printf("%d (?) Falsche Eingabe!!\n", n);
}
ABFRAGE0: {
int i = 0, j = 0;
for (i = 0; i < TAGE; i++) {
printf("\n\t[Eingeloggt als: %s ] Tag %d in der Woche\n", vorname, i + 1);
printf("\t-------------------\n\n");
for (j = 0; j < ARBEITER; j++) {
printf("Arbeiter Nr.%d in Std.: ", j + 1);
scanf("%ld", &zeitkonto[j][i]);
if (zeitkonto[j][i] > 24) {
printf("Ein Tag hat nur 24 Stunden?\n");
PCLEAR WHALLOWELT ABSATZ goto ABFRAGE0;
}
if (zeitkonto[j][i] > 47) {
printf("Wer wünscht sich nicht, man hätte mehr Zeit?");
PCLEAR WHALLOWELT ABSATZ goto ABFRAGE0;
}
}
}
}
我做错了什么?
【问题讨论】:
-
什么是“点数”?这段代码应该做什么?实际发生了什么?
-
您能否将代码缩小到您遇到问题的一个功能?
-
我的意思是像“5.5”之类的数字。它应该读取他们每天工作多长时间并计数到第 5 天。之后其他功能能够说出每天的平均工作时间是多少,哪个工人在哪一天工作了多长时间等等..只是一些测试功能。
-
尝试编写尽可能小的测试程序来重现此类问题。这里 5 行就足够了。
-
告诉扫描仪读取整数时,无法读取浮点值。
标签: c arrays loops floating-point numbers