在这里,我想要一个不。这是 5 的倍数应该在 'if' 中执行,但是没有。这不是 5 的倍数不应该执行,打印 'else'

Here I want that a no. which is multiple of 5 should be executed in 'if' but the no. which is not the multiple of 5 shouldn't execute, print 'else'

定义:求解 ATM 问题

#include <stdio.h>
int main(void)
{
    // your code goes here
    float x;
    float y = 2000;
    printf("Instruction: This ATM accepts values which are multiple of 5 \n");
    printf("Enter the amount to withdraw: \n");
    scanf("%f", &x);
    if (x / 5 && x <= y)
    {
        float z = y - x;
        float a = z - 0.5;
        printf("Your Transaction is successful\n\n");
        printf("Your Account Balance is %f\n\n", a);
    }
    else
    {
        printf("Error: %f\n\n", x);
        printf("Read the Instruction carefully\n\n");
    }
    return 0;
}

您可以使用fmodf来检查两个float的余数,例如:

#include <stdio.h>
#include <math.h>

int main(void)
{
    float a = 25.0f;
    float b = 25.1f;

    printf("%f divisible by 5 = %s\n", a, fmodf(a, 5.0f) == 0 ? "true" : "false");
    printf("%f divisible by 5 = %s\n", b, fmodf(b, 5.0f) == 0 ? "true" : "false");
    return 0;
}

输出:

25.000000 divisible by 5 = true
25.100000 divisible by 5 = false

你的情况:

if((fmodf(x, 5.0f) == 0) && (x<=y))