dimanche 8 novembre 2015

code breaks after if else function in C

So my code keeps breaking after the ending curly brace in my if else function I made. Does it have something to do with the return EXIT_SUCCES, am I using it wrong?

Here's my code:

//  recursive.c
//  lynda

#include <stdio.h>
#include <stdlib.h>
/*
 checks for traffic light if else example
 */
void processColor(char c);
void checkTraficLight(void);
int main(void){
    checkTraficLight();
    return EXIT_SUCCESS;
}

void checkTraficLight(void){
    printf("what is the light? r, y, g: \n");
    char color;
    scanf("%c", &color);
    processColor(color);
}

void processColor(char c){
    if (c == 'r') {
        printf("color is red");
    } else if (c == 'y'){
        printf("color is yellow");
    } else if(c == 'g'){
        printf("color is green");
    } else {
        printf("U entered an invalid color");
    }
}

Aucun commentaire:

Enregistrer un commentaire