0

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

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by sundip
1

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;
}
Votes + Comments
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!!

Edited by myrongainz: n/a

0
#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
 
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.