Hi guy, I need to create a program that sorts 3 words entered into order from shortest to longest. So far I have the following done but when I run it, it only displays the first two words in order of length and doesnt show the 3rd word. Can anyone tell me what is wrong with it?
#include<iostream>
#include<string>
using namespace std;
int main()
{
int num1,num2,num3,ntemp, count = 0;
string name1,name2,name3,stemp;
cout << "enter 3 words.\n";
cin >> name1 >> name2 >> name3;
num1 = name1.length();
num2 = name2.length();
num3 = name3.length();
while (count <= 1)
{
if (num1 > num2)
{
num1 = ntemp;
num1 = num2;
num2 = ntemp;
name1 = stemp;
name1 = name2;
name2 = stemp;
}
if ( num2 > num3 )
{
num2 = ntemp;
num2 = num3;
num3 = ntemp;
name2 = stemp;
name2 = name3;
name3 = stemp;
}
count++;
}
cout << name1 << " " << name2 << " " << name3 << " ";
system("pause");
return 0;
}