简体   繁体   中英

Wrong result outputted

I am writing a code that will output "Nice work!" if the entered GPA is over 3.5 and "you need to study harder if the entered GPA is under 2.0. But it is not outputting correctly.

if(gpa[i] >= 2.0){
printf("You need to study harder! \n");
}
else if(gpa[i] <= 3.5){
printf("Nice work! \n");
}

I expect the output "nice work!" if the gpa is over 3.5. and "you need to study harder" if the gpa is under 2.0.

You confused with the logical operator within if condition. It should be like

if(gpa[i] <= 2.0){
    printf("You need to study harder! \n");
}
else if(gpa[i] >= 3.5){
    printf("Nice work! \n");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM