【问题标题】:Runtime error occurs what is the problem?出现运行时错误是什么问题?
【发布时间】:2023-03-15 02:44:02
【问题描述】:

我试图找到平均值,但这无法解决。此代码显示“运行时错误”请帮助我,我的代码在这里:

cin >> n;

    while (n > 100 || n <= 0)
    {
        cout << "Error! number should in range of (1 to 100)." << endl;
        cout << "Enter the number again: ";
        cin >> n;
    }

【问题讨论】:

  • 什么是n,它在哪里定义?请参阅How to create a Minimal, Reproducible Example,然后发布完整的代码、您输入的输入以及您收到的确切错误消息。
  • 运行时错误似乎不会从此代码 sn-p...
  • 如果这是关于运行时错误,为什么您的问题会被标记为“语法错误”?

标签: c++ syntax-error


【解决方案1】:

我不明白 'n' 代表什么。我发现你的脚本有一些问题。首先你应该定义'n'。其次,最好不要使用循环进行检查。 第三,我建议你使用这个代码”:

int n;
cin>>n;
if(n>100 && n<0)
{
   cout << "Error! number should in range of (1 to 100)." << endl;
   cout << "Enter the number again: ";
   cin >> n;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    相关资源
    最近更新 更多