Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please include step by step directions. Thank you. 13. Use the algorithm from th

ID: 3585624 • Letter: P

Question

Please include step by step directions. Thank you.

13. Use the algorithm from the Sample Solutions that reads in 3 numbers and prints them in order. You do not have to include the entire algorithm. Use the phrase "Call Sort" (or something similar) instead.
Enclose the algorithm within a loop that reads in the three values until the user enters the first value of the trio as negative.
Rewrite the algorithm above so that the user has to enter only one negative value to stop (that is, the second and third values are not entered).

Explanation / Answer

Hi Let me know if you need more information:-

=================================

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

   int first, second, third;
   int tmp = 0;
   while (true) {

       cout << "Enter 1st:" << endl;
       cin >> first;
       cout << "Enter 2nd:" << endl;
       cin >> second;
       if (first == (-1 * second))
           break;
       cout << "Enter 3rd:" << endl;
       cin >> third;
       if (first == (-1 * third))
           break;

       cout << "Before: " << first << ":" << second << ":" << third << endl;

       if (first > third)
           swap(first, third);

       if (first > second)
           swap(first, second);

       if (second > third)
           swap(second, third);

       cout << "Sorted: " << first << ":" << second << ":" << third << endl;
   }
   return 0;
}

========================

OUTPUT:-

====================

Enter 1st:
3
Enter 2nd:
4
Enter 3rd:
1
Before: 3:4:1
Sorted: 1:3:4
Enter 1st:
3
Enter 2nd:
-3

===============

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

   int first, second, third;
   int tmp = 0;
   while (true) {

       cout << "Enter 1st:" << endl;
       cin >> first;
       if (first < 0)
           break;
       cout << "Enter 2nd:" << endl;
       cin >> second;
       if (second < 0)
           break;
       cout << "Enter 3rd:" << endl;
       cin >> third;
       if (third < 0)
           break;

       cout << "Before: " << first << ":" << second << ":" << third << endl;

       if (first > third)
           swap(first, third);

       if (first > second)
           swap(first, second);

       if (second > third)
           swap(second, third);

       cout << "Sorted: " << first << ":" << second << ":" << third << endl;
   }
   return 0;
}


============

OUTPUT:-

===================================

Enter 1st:
3
Enter 2nd:
92
Enter 3rd:
1
Before: 3:92:1
Sorted: 1:3:92
Enter 1st:
3
Enter 2nd:
5
Enter 3rd:
6
Before: 3:5:6
Sorted: 3:5:6
Enter 1st:
3
Enter 2nd:
-9


=============

=======

Thanks