Question: Write a program that takes two strings and outputs the longest string. If they are the same length, output this message: same length. Ex. If
Write a program that takes two strings and outputs the longest string. If they are the same length, output this message: "same length". Ex. If the input is: almond pistachio the output is: pistachio use c++ code below and improvise #include #include using namespace std; int main() { string str1, str2; cout << "Enter string 1: "; getline(cin, str1); cout << "Enter string 2: "; getline(cin, str2); if (str1.length() > str2.length()) { cout << "Longest string is: " << str1 << endl; } else if (str1.length() < str2.length()) { cout << "Longest string is: " << str2 << endl; } else { cout << "Both strings are the same length." << endl; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
