Answer:
Following are the code to the given question:
#include <iostream>//header file
using namespace std;
int main()//main method
{
int first = 0,second = 0,third = 0;//defining integer variable
int temp; //defining integer variable
const string SENTINEL = "done"; // defining a string variable as constant
string repeat;// defining a string variable
bool notDone = true; //defining bool variable
cout << "Enter first number: ";//print message
cin >> first;//input value
cout << "Enter second number: ";//print message
cin >> second;//input value
cout << "Enter third number: ";//print message
cin >> third;//input value
while(notDone == true)//defining a loop to check the value
{
if(first > second)//use if to compare first and second value
{
int temp = first;//defining temp to hold first value
first = second;//holding second value in first variable
second = temp;//holding temp value in second variable
}
if(second > third)//use if to compare second and third value
{
int temp = second;//defining temp to hold second value
second = third;//holding second value in third variable
third = temp;//holding temp value in third variable
}
cout << "Smallest: " << first << endl;//print smallest value
cout << "Next smallest: " << second << endl;//print Next smallest value
cout << "Largest: " << third << endl;////print Largest value
cout << "Enter any letter to continue or done to quit: ";//print message
cin >> repeat;//holding string value
if (repeat == SENTINEL)
{
notDone = false;//holding bool value
}
else //else block
{
cout << "Enter first number: ";//print message
cin >> first;//input value
cout << "Enter second number: ";//print message
cin >> second;//input value
cout << "Enter third number: ";//print message
cin >> third;//input value
}
return 0;
}
}
Output:
Please find the attached file.
Explanation:
- Inside the main method Four integer variable "first, second, third, and temp" is declared in which first three variable is used for input value and temp is used to compare value.
- In thew next step, two string variable "SENTINEL and repeat" is declared in which "SENTINEL" is constant and a bool variable "notDone" is declared.
- After input the value from the user-end a loop is declared that compare and swap value and print its value.