简体   繁体   English

项目未编译,但Code :: Blocks中没有警告或错误

[英]Project not compiling with no warnings or errors in Code::Blocks

I am going trough the book C Programming: A Modern Approach (KN King) and I am on chapter 2. I have done almost every exercise and program, but I have trouble with program #7. 我正在读《 C程序设计:一种现代方法》 (KN King)一书,我将学习第2章。我几乎完成了所有练习和程序,但是在程序#7上遇到了麻烦。

Basically, it asks you to write a program that calculates the minimum amount of dollar bills you need for a specific amount. 基本上,它要求您编写一个程序来计算特定金额所需的最低美元金额。 I have written the program and it works fine for bills of 20, 10, 5 and 1. But if I copy part of the code to use it for $50 bills, the file won't compile. 我已经编写了该程序,它对于20、10、5和1的钞票正常工作。但是,如果我复制部分代码以将其用于50美元的钞票,则该文件将无法编译。

Here is my code: 这是我的代码:

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;

The program works perfectly, until I try to use the part I commented out (it is a copy of the other blocks, but with a number 20 instead of 10 for example). 该程序运行良好,直到我尝试使用我注释掉的部分为止(它是其他块的副本,但以数字20代替10)。

The compiler gives no warnings or errors, it just won't compile. 编译器不会发出警告或错误,只会编译。 How do I fix this? 我该如何解决?

The solution to my problem was totally not C related as the code did in fact compile and try to run. 我的问题的解决方案完全不与C相关,因为代码实际上可以编译并尝试运行。

It turns out my antivirus blocked the .exe form running or something like that. 事实证明,我的防病毒软件阻止了.exe表单的运行或类似的行为。 I have no idea how and why in the world it would do it, but it did. 我不知道世界上它将如何以及为什么会这样做,但是确实做到了。 As i disabled "Avast Free Antivirus" the code worked like a charm. 当我禁用“ Avast Free Antivirus”时,代码像个魅力一样起作用。

Thanks to Wather Vane for testing my code. 感谢Wather Vane测试我的代码。 You made me belive I didn't go insane yet :) 你让我相信我还没发疯:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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