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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!