in

One If-Else statement is always read


I’m currently having a problem with my code specifically the If-else part. If my year-level is 1, the if-else is satisfied but if the year-level I’ll input is 2, 3 or 4, the if-else for these are satisfied HOWEVER, it always displays the if-else for yrep1 (It always prints “Year-level Representative: Lady Carmel”) except if the year-level is 1.

int year, yrep1, yrep2, yrep3, yrep4;

char gov1[] = "Juan Dela Cruz";
...
char fiy1[] = "Lady Carmel";

printf("nEnter Year Level: ");
scanf("%d", &year);

if(year==1){
    
    printf("nnttt CANDIDATES FOR FIRST YEAR LEVEL REPRESENTATIVE ");
    printf("nn1. Lady Carmel");
    printf("nn2. Zia Alonzo");
    
    printf("nnEnter your vote(Ex. 1): ");
    scanf("%d", &yrep1);

    printf("nVote has been recorded!");
    
}else if (year==2){
    
    printf("nnttt CANDIDATES FOR SECOND YEAR LEVEL REPRESENTATIVE ");
    printf("nn1. Lita Cordova");
    printf("nn2. Mariel Geronimo");
    
    printf("nnEnter your vote(Ex. 1): ");
    scanf("%d", &yrep2);
    
    printf("nVote has been recorded!");
    
}else if (year==3){
    
    printf("nnttt CANDIDATES FOR THIRD YEAR LEVEL REPRESENTATIVE ");
    printf("nn1. Carmel De Leon");
    printf("nn2. Helen Sy");
    
    printf("nnEnter your vote(Ex. 1): ");
    scanf("%d", &yrep3);
    
    printf("nVote has been recorded!");
    
}else if (year==4){
    
    printf("nnttt CANDIDATES FOR FOURTH YEAR LEVEL REPRESENTATIVE ");
    printf("nn1. Stephen Cortes");
    printf("nn2. Olivia Yu");
    
    printf("nnEnter your vote(Ex. 1): ");
    scanf("%d", &yrep4);
    printf("nVote has been recorded!");
}

if(yrep1==1){
    printf("nntYear-level Representative: %s", fiy1);
}else if(yrep1==2){
    printf("nntYear-level Representative: %s", fiy2);
}

if(yrep2==1){
    printf("nntYear-level Representative: %s", sy1);
}else if(yrep2==2){
    printf("nntYear-level Representative: %s", sy2);
}

if(yrep3==1){
    printf("nntYear-level Representative: %s", ty1);
}else if(yrep3==2){
    printf("nntYear-level Representative: %s", ty2);
}

if(yrep4==1){
    printf("nntYear-level Representative: %s", foy1);
}else if(yrep4==2){
    printf("nntYear-level Representative: %s", foy2);
}
printf("nntttttBALOT RECEIPT");
printf("nntNAME: %s", name);
printf("tttttDATE: %s", ctime(&t));
printf("ntYEAR LEVEL: %d", year);
printf("nntYEAR SECTION: %s", section);
printf("nntttYOU'VE VOTED FOR THE FOLLOWING CANDIDATES:");



Source: https://stackoverflow.com/questions/70605643/one-if-else-statement-is-always-read

Flutter Google One Tap Sign In (Android)

How ADP HR and Payroll Solutions Can Help Your Growing Business