[英]Project not compiling with no warnings or errors in Code::Blocks
我正在讀《 C程序設計:一種現代方法》 (KN King)一書,我將學習第2章。我幾乎完成了所有練習和程序,但是在程序#7上遇到了麻煩。
基本上,它要求您編寫一個程序來計算特定金額所需的最低美元金額。 我已經編寫了該程序,它對於20、10、5和1的鈔票正常工作。但是,如果我復制部分代碼以將其用於50美元的鈔票,則該文件將無法編譯。
這是我的代碼:
int x, num, rest ;
printf("Insert amount to pay: ");
scanf("%d", &x);
printf("You will use the least amount of bills if you pay like so: \n");
num = x / 50;
rest = x - num * 50;
printf("$%d bills: %d\n", 50, num);
/*
num = rest / 20;
rest = rest - num * 20;
printf("$%d bills: %d\n", 20, num);
*/
num = rest / 10;
rest = rest - num * 10;
printf("$%d bills: %d\n", 10, num);
num = rest / 5;
rest = rest - num * 5;
printf("$%d bills: %d\n", 5, num);
num = rest;
printf("$%d bills: %d\n", 1, num);
return 0;
該程序運行良好,直到我嘗試使用我注釋掉的部分為止(它是其他塊的副本,但以數字20代替10)。
編譯器不會發出警告或錯誤,只會編譯。 我該如何解決?
我的問題的解決方案完全不與C相關,因為代碼實際上可以編譯並嘗試運行。
事實證明,我的防病毒軟件阻止了.exe表單的運行或類似的行為。 我不知道世界上它將如何以及為什么會這樣做,但是確實做到了。 當我禁用“ Avast Free Antivirus”時,代碼像個魅力一樣起作用。
感謝Wather Vane測試我的代碼。 你讓我相信我還沒發瘋:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.