#include <iostream>
#include <cstdio>
#include <cstdlib>
class BankAccount
{
public:
int CheckIntegrity(int input)
{
int allowed[6] ={};
int i{};
if (input < allowed[i])
{
std::cout << "Accepted";
}
else
{
std::cout << "Exited with 0";
}
return 0;
}
};
int main()
{
BankAccount accounts;
int numbers;
std::cout << "Enter account number ";
std::cin >> numbers;
accounts.CheckIntegrity(numbers);
}
我不确定为什么在Visual Studio中运行代码时显示为0退出?有关如何解决此问题的任何线索。被困了一个小时试图解决这个问题
答案 0 :(得分:1)
allowed []数组包含全零。因此,如果输入任何值,请说x,其中 0> = x> = INT_MAX,您的代码将显示“ Exited with 0”。 任何负数应打印“已接受”。可能是您代码中的逻辑错误。
我在Xcode中运行了您的代码。如果有帮助,请尝试使用断点进行调试。
答案 1 :(得分:0)
通常的方法是在结束括号处添加断点,以在退出前检查结果。
另一种方法是转到“工具”>“选项”>“调试”,然后取消选中“调试停止时自动关闭控制台”。