C++ 从一个数字向上计数到另一个数字

C++ Counting upwards from one number to another

本文关键字:数字 另一个 一个 C++      更新时间:2023-10-16

所以我的程序必须要求用户输入两个数字,然后程序必须找出哪个是最低的数字,哪个是最高的数字。然后程序从最低到最高计数并显示它(例如 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;
    }

你永远不会修改minmax。 在main开始时将它们设置为 0 和 4,并且从不更新它们。