簡體   English   中英

誰能指出我在代碼中犯了什么錯誤?

[英]Can anyone point out what mistake I made in my code?

Pooja 想從 ATM 取款 X 美元。 只有當X是5的倍數,並且Pooja的賬戶余額有足夠的現金來執行取款交易(包括銀行手續費)時,提款機才會接受交易。 對於每次成功的提款,銀行收取 0.50 美元。 在嘗試交易后計算 Pooja 的賬戶余額。

#include <stdio.h>
int main(void)
{
    float initialamt;
    int deductamt =0;
// taking input of the account balance and money to be withdrawn 
    scanf("%f", &initialamt);
    scanf("%d", &deductamt);
// Checking if the mat is a multiple of 5 and less than act balance
    if(deductamt%5 ==0 && deductamt<= initialamt-0.50)
    {
        initialamt = initialamt - deductamt -0.50;
        printf("%2f", initialamt);
    }
    else
    {
        printf("%2f", initialamt);
    }
    return 0;
}

我在 CodeChef 上找到了問題,你的問題是https://www.codechef.com/problems/HS08TEST嗎?

那么問題輸入的是deduct - init balance in order,而不是init balance - deduct in order,所以只要切換scanf即可。

scanf("%d", &deductamt);
scanf("%f", &initialamt);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM