Q:

Write a program to read two strings and report whether the strings are equal. If not, report which of the two is larger. Now, change the program to report whether the strings have the same length, and if not, report which is longer

0

Write a program to read two strings and report whether the strings are equal. If not, report which of the two is larger. Now, change the program to report whether the strings have the same length, and if not, report which is longer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <string>

void check_equal() {
  std::string s1, s2;
  if (std::cin >> s1 >> s2) {
    if (s1 == s2)
      std::cout << "The two strings are equal." << std::endl;
    else if (s1 > s2)
      std::cout << "The first string is larger." << std::endl;
    else
      std::cout << "The second string is larger." << std::endl;
  }
}

void check_length() {
  std::string s1, s2;
  if (std::cin >> s1 >> s2) {
    if (s1.size() == s2.size())
      std::cout << "The two strings have same length." << std::endl;
    else if (s1.size() > s2.size())
      std::cout << "The first string is longer." << std::endl;
    else
      std::cout << "The second string is longer." << std::endl;
  }
}

int main() {
  //check_equal();
  //check_length();

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now