Runtime error in C code (strange double conversion)

Posted by Miro Hassan on Stack Overflow See other posts from Stack Overflow or by Miro Hassan
Published on 2013-11-02T21:32:15Z Indexed on 2013/11/02 21:53 UTC
Read the original article Hit count: 136

Filed under:

I have a strange runtime error in my C code. The Integers comparison here works fine. But in the Decimals comparison, I always get that the second number is larger than the first number, which is false. I am pretty new to C and programming in general, so this is a complex application to me.

#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();
}
}

© Stack Overflow or respective owner

Related posts about c