samedi 7 novembre 2015

Program breaks on if else function in C

So my code is breaking at my if else function, I've ran through my code several times now and haven't been able to find my bug.

Is there anyone who can give me some pointers to what I've been messing up?

//  recursive.c
//  lynda

#include <stdio.h>
#include <stdlib.h>

// prototypes
int getNumber(void);
void checkError(int num);
void tooLarge(void);
void tooSmall(void);
int num;

//main
int main(void){

    int num = getNumber();
    if ((num >= 0)&&(num <= 100)){
        printf("Just right");
    } else{
        checkError(num);
         return EXIT_SUCCESS;
    }


}
int getNumber(void){
    int num;
    printf("Enter a number between 0 and 100: ");
    scanf("%d", &num);
    return num;
}

void checkError(int num){
    if (num < 0) {
        tooSmall();
    } else {
        tooLarge();
    }
}

void tooSmall(void){
    printf("The number is too small\n");
}

void tooLarge(void){
    printf("The number is too big\n");
}

Aucun commentaire:

Enregistrer un commentaire