我遇到了c代码问题,即测试三角形。 我想将第一个问题的输入限制为1到255之间的数字。 这到目前为止工作。但是如果输入错误,我也想要包含错误。
在要求用户键入第一,第二和第三个数字的部分,我希望它只接受0.0< FLT_MAX。我再次希望它在错误输入时提示错误,然后再次询问该号码。
任何帮助都将不胜感激。
谢谢,
Dommas
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ROW 255
#define COLUMN 3
#define B 0
#define COL 0
int count;
int x = 0;
int a = 0;
double zahl[ROW][COLUMN];
int main()
{
memset(zahl, 0, sizeof(zahl[0][0]) * ROW * COLUMN);
char input[255];
int first = 0;
//read input
do
{
printf("Please enter the number of triangles to check: ");
if(fgets(input, sizeof(input), stdin) == NULL)
{
return 0;
}
first = atof(input);
} while(first < 1 || first > ROW);
for (count = 0; count < first; count++) {
printf("Please enter the first number of the triplet: ");
scanf("%lf", &zahl[x][COL]);
printf("Please enter the second number of the triplet: ");
scanf("%lf", &zahl[x][COL+1]);
printf("Please enter the third number of the triplet: ");
scanf("%lf", &zahl[x][COL+2]);
x++;
}
}