Advertisement
Spocoman

09. Greater of Two Values

Nov 17th, 2023
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string stringGreaterValue(string s1, string s2) {
  7.     return s1 > s2 ? s1 : s2;
  8. }
  9.  
  10. char charGreaterValue(char c1, char c2) {
  11.     return c1 > c2 ? c1 : c2;
  12. }
  13.  
  14. int intGreaterValue(int n1, int n2) {
  15.     return n1 > n2 ? n1 : n2;
  16. }
  17.  
  18. int main() {
  19.     string type;
  20.     cin >> type;
  21.     cin.ignore();
  22.  
  23.     string firstValue, secondValue;
  24.     getline(cin, firstValue);
  25.     getline(cin, secondValue);
  26.  
  27.     if (type == "int") {
  28.         cout << intGreaterValue(stoi(firstValue), stoi(secondValue));
  29.     }
  30.     else if (type == "char") {
  31.         cout << charGreaterValue(firstValue.at(0), secondValue.at(0));
  32.     }
  33.     else if (type == "string") {
  34.         cout << stringGreaterValue(firstValue, secondValue);
  35.     }
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement