C++从一个数到另一个数的计数

C++从一个数到另一个数的计数,c++,counting,C++,Counting,因此,我的程序必须要求用户输入两个数字,然后程序必须计算出哪个数字最低,哪个数字最高。然后程序从最低到最高计数并显示,例如3、4、5、6。我认为问题在于if-else语句,但我不确定 using namespace std; void no_1_count_from_min_to_max(int min, int max); int main() { int min=0; int max=4; int first; int second; int thir

因此,我的程序必须要求用户输入两个数字,然后程序必须计算出哪个数字最低,哪个数字最高。然后程序从最低到最高计数并显示,例如3、4、5、6。我认为问题在于if-else语句,但我不确定

using namespace std;
void no_1_count_from_min_to_max(int min, int max);
int main()
{
    int min=0;
    int max=4;
    int first;
    int second;
    int third;

    cout<<"Enter first number:";
    cin>>first;
    cout<<endl;
    cout<<"Enter second number:";
    cin>>second;
    cout<<endl;
    cout<<"Enter third number:";
    cin>>third;
    cout<<endl;

    no_1_count_from_min_to_max(min,max);

    if (first>second){
        first = max;
        second = min;
    }
    else{
        second = max;
        first = min;
    }
    return 0;
}
    void no_1_count_from_min_to_max(int min, int max){
        for (int i = min; i<=max; i++){
            cout<<setw(4)<<i;
        }
        cout<<endl;
    }

您从不修改最小值或最大值。您在main的开头将它们设置为0和4,并且从不更新它们。

什么问题?听起来您可能需要学习如何使用调试器逐步完成代码。有了一个好的调试器,您可以逐行执行您的程序,并查看它偏离预期的地方。这是一个必要的工具,如果你要做任何编程。进一步阅读:您要求用户输入一些数字,然后立即用您的硬编码值覆盖它们。那么,询问数字的目的是什么?first=max意味着首先设置max的值。我想你是想设置max?您也在输出后执行所有这些操作。请尝试更简单的操作。说真的,你应该试着从简单到复杂,如果你不知道为什么你的代码会失败,那就试着简化它。如果你找到了解决方案,不要编辑问题,说明你做了。接受答案,这就是解决方案。如果没有,请自己写下答案,并接受它。否则,您的编辑不会向任何人传达任何有用的信息。从技术上讲,这些数字是0和4,而不是0和1。