by CodeChum Admin
Most, if not all things have numeric values. That goes for characters too. In order to find out which character has a higher value, we have to compare them with each other and display the value of the higher character.
Instructions:
Input
1. First character
2. Second character
Output
Enter·first·character:·a
Enter·second·character:·h
Result·value·=·104
#include <iostream>
using namespace std;
int getHigherValue(char ch1, char ch2) {
if (ch1 > ch2)
return ch1;
else
return ch2;
}
int main() {
char ch1, ch2;
cout << "First character: ";
cin >> ch1;
cout << "Second character: ";
cin >> ch2;
cout << "Result value = " << getHigherValue(ch1, ch2) << endl;
return 0;
}
Comments
Leave a comment