我的 C 代码中有一个奇怪的运行时错误。这里的Integers
比较效果很好。但在Decimals
比较中,我总是得到第二个数字大于第一个数字,这是错误的。我对 C 和一般编程很陌生,所以这对我来说是一个复杂的应用程序。
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int choose;
long long neLimit = -1000000000;
long long limit = 1000000000;
bool big(a,b) {
if ((a >= limit) || (b >= limit))
return true;
else if ((a <= neLimit) || (b <= neLimit))
return true;
return false;
}
void largerr(a,b) {
if (a > b)
printf("\nThe First Number is larger ..\n");
else if (a < b)
printf("\nThe Second Number is larger ..\n");
else
printf("\nThe Two Numbers are Equal .. \n");
}
int main() {
system("color e && title Numbers Comparison && echo off && cls");
start:{
printf("Choose a Type of Comparison :\n\t1. Integers\n\t2. Decimals \n\t\t I Choose Number : ");
scanf("%i", &choose);
switch(choose) {
case 1:
goto Integers;
break;
case 2:
goto Decimals;
break;
default:
system("echo Please Choose a Valid Option && pause>nul && cls");
goto start;
}
}
Integers: {
system("title Integers Comparison && cls");
long x , y;
printf("\nFirst Number : \t");
scanf("%li", &x);
printf("\nSecond Number : ");
scanf("%li", &y);
if (big(x,y)) {
printf("\nOut of Limit .. Too Big Numbers ..\n");
system("pause>nul && cls") ; goto Integers;
}
largerr(x,y);
printf("\nFirst Number : %li\nSecond Number : %li\n",x,y);
goto exif;
}
Decimals: {
system("title Decimals Comparison && cls");
double x , y;
printf("\nFirst Number : \t");
scanf("%le", &x);
printf("\nSecond Number : ");
scanf("%le", &y);
if (big(x,y)) {
printf("\nOut of Limit .. Too Big Numbers ..\n");
system("pause>nul && cls") ; goto Decimals;
}
largerr(x,y);
goto exif;
}
exif:{
system("pause>nul");
system("cls");
main();
}
}