Sinux1

PS8Q5.cpp

May 3rd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void comes_before(string wrd1, string wrd2)
  5. {
  6.     cout << "\"" << wrd1 << "\"" << " comes before \"" << wrd2 << "\".\n";
  7. }
  8.  
  9. void comes_after(string wrd1, string wrd2)
  10. {
  11.     cout << "\"" << wrd1 << "\"" << " comes after \"" << wrd2 << "\".\n";
  12. }
  13.  
  14.  
  15. void str_compare(string word1, string word2)
  16. {
  17.     if (word1 == word2)
  18.     {
  19.         cout << "Words are exactly the same.\n";
  20.     }
  21.     else if (word1 > word2)
  22.     {
  23.         comes_after(word1, word2);
  24.     }
  25.  
  26.  
  27.     else if(word1 < word2)
  28.     {
  29.         comes_before(word1, word2);
  30.     }
  31.  
  32. }
  33.  
  34. int main()
  35. {
  36.     string s1, s2;
  37.  
  38.     cout << "== String Compare ==\n";
  39.     cout << "Enter a word\n";
  40.     cin >> s1;
  41.     cout << "Enter another word\n";
  42.     cin >> s2;
  43.  
  44.     str_compare(s1, s2);
  45.  
  46.     return 0;
  47. }
Add Comment
Please, Sign In to add comment