Need help with program

i recently started learning c++ and i have been given a question and no one seems to be able to get it in my class. I have to write a piece of programming. the program has to accept 3 positive numbersas inputs and print it out in accending order. if a negative number is inputted it should show a message to re enter a correct number . Any help will be appreciated.

which part can no one get ?

your sudo code would be
if num1 > num2 & num3
if num2 > num3
num1 num2 num3
else
num1 num3 num2

else
if num2 > num1 & num3
chk if num1 is larger than 3

else
if num3 > num1 & num2
chk if num1 is larger than 2
but how to apply the code to loop back if a negative number is inputted
this is what i have so far

#include <iostream>
using namespace std;
int main()

{
int num1;
int num2;
int num3;
int exit;


cout << "Please type the first number and press Enter." << endl;
cin >> num1;
cout << " " << endl;
cout << "Please type the second number and press Enter." << endl;
cin >> num2;
cout << " " << endl;
cout << "Please type the third number and press Enter." << endl;
cin >> num3;
cout << " " << endl;

if (num1<num2 && num2<num3)
cout<< num1 << num2 << num3;
if (num1<num3 && num3<num2)
cout<< num1 << num3 << num2;
if (num2<num1 && num1<num3)
cout<< num2 << num1 << num3;
if (num2<num3 && num3<num1)
cout<< num2 << num3 << num1;
if (num3<num2 && num2<num1)
cout<< num3 << num2 << num1;
if (num3<num1 && num1<num2)
cout<< num3 << num1 << num2;

cout << " " << endl;
cout << "Type 'exit' to exit." << endl;
cin >> exit;

system ("pause");
return 4;

}

...it works i just confused on how to enter a loop to stop negative numbers from entering and it has to show a message also!
i was thinking to use an if else function but im a bit confused on how to loop it back after the first entry
can anyone help me
Since you have to do the same thing three times, you should put the logic in a function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;

//  Does not return until a positive number has been entered; 
int get_positive_integer (int n)
{   int num;

    do
    {   
        cout << "Please enter number " << n << ": "; 
        cin >> num;
    } while (num < 0);
    return num;
}

int main()
{   int num1;
    int num2;
    int num3;

    num1 = get_positive_integer (1);
    num2 = get_positive_integer (2);
    num3 = get_positive_integer (3);

    if (num1<num2 && num2<num3)
        cout<< num1 << num2 << num3;
    if (num1<num3 && num3<num2)
        cout<< num1 << num3 << num2;
    if (num2<num1 && num1<num3)
        cout<< num2 << num1 << num3;
    if (num2<num3 && num3<num1)
        cout<< num2 << num3 << num1;
    if (num3<num2 && num2<num1)
        cout<< num3 << num2 << num1;
    if (num3<num1 && num1<num2)
        cout<< num3 << num1 << num2;

    system ("pause");
    return 0;   //  A successful program should always return 0
}


BTW, you can't enter 'exit' into an int.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Topic archived. No new replies allowed.