Hello,
basically I'm trying to write a program where you ask the user to input 2 positive number. Then the program will print the lower of the two numbers to the higher of the 2 numbers and then higher of the 2 numbers to the lower of the 2 numbers. But I'm still stuck on the first part...

#include <iostream>

using namespace std;

int main()
{

int num1, num2, number=0;
    cout<<"Please enter your first number"<<endl;

    while (num1 >= number)
{
    cin>>num1;
    if(num1<number)
    {
    cout<<"Please enter a positive number"<<endl;
    cin>>num1;
    }
}


    cout<<"Please enter you second number"<<endl;
    while (num2<number)
{
    cout<<"Please enter a positive number"<<endl;
    cin>>num2

}
    cin>>num2;

basically it does not distinguish if the number is positive or not...
and yes I'm still a beginner

if you want to get a positive number from the user try this out.

int number = -1;
while(number < 0)
{
    cout << "please enter a positive integer: ";
    cin >> number;
}
commented: thanks man +0

if you want to get a positive number from the user try this out.

int number = -1;
while(number < 0)
{
    cout << "please enter a positive integer: ";
    cin >> number;
}

NVM i get it thanks!!

#include <iostream>
 
using namespace std;
 
int main()
{
 
int num1, num2, number=0;

cout<<"Please enter your first number"<<endl;
cin>>num1;
 
while(num1<number)
{
    cout<<"Please enter a positive number"<<endl;
    cin>>num1;
}

 
 
cout<<"Please enter you second number"<<endl;
cin>>num2;

while (num2<number)
{
    cout<<"Please enter a positive number"<<endl;
    cin>>num2
 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.