vendredi 21 avril 2017

Why only else statement is working, if statement is not executing in my code? [duplicate]

This question already has an answer here:

I choosed case 1 and else statement is works before scanf.

int main(){
int x;
int y;
char a;
char b;
int c;
int choose;
printf("Which shape would you like to draw?\n 1. Line\n 2. Parabola\n 3. Circle\n 4. Exit\n");
scanf("%d",&choose);
switch(choose){


                            case 1:{                                    

                                printf("Line formula is y = ax + b \n Enter a and b\n");                                    
                                scanf("%c",&a);
                                if(isdigit(a)){
                                    scanf("%c",&b);

                                int height = 10+abs(b);
                                int width = 10+abs(a);
                                int y = height;
                                for (; y >= -10-abs(b); y--){
                                int x = -10-abs(a);       
                                        for (; x <= width; x++){                        
                                                printf(Line (x,y,a,b));                 
                                            }                           
                                            printf("\n");           

                                            }
                                }
                                else {
                                printf("hata");                                 
                                //scanf("%d",&b);
                        }
                                            break;
                                        }

I want the user can enter only an integer value. It makes sense to use this method. You can help if there is another method of exception handling.

Aucun commentaire:

Enregistrer un commentaire