I have another assignment in which it asks for two words and then compare them to write the first one and then the other. I think I have solved the first one but it's doesn't show the second word. the program that I write is
#include<iostream>
using namespace std;
int main() {
// prints two words and compare them
string x, y;
// user type the words taken by x and y respectively
cout << " x = " << x << " and y = " << y << endl;
cin >> x >> y;
// comapre two words
if(x < y) cout << " the first word is: " << x << endl;
else cout << " the second word is: " << y << endl;
return 0;
}
Please help me out.
Let my guys give you the whole question
Create a C++ program that accepts two words adn compare them. The output should say " the frist word is: " then the first word in alphabetic order should appear, and in other line " the second word is: " then the second word typed by the user.
Yea, the way C++ will technically "compare" strings, like if i was asking which one was greater, it will look at the strings memory address. Your best bet will be to compare their size.
Create a C++ program that accepts two words adn compare them. The output should say " the frist word is: " then the first word in alphabetic order should appear, and in other line " the second word is: " then the second word typed by the user.
yes i know i write down the compare function but it's only shows only one value which less but i have to have both values such this way- lower value showing on one line than the higher value showing in another line
If it's just two words. You can do something like this. Real simple. But further on down the line you might want to do something else that is more portable than if-else statement. hehe. :)