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 a, char b)
{
if (a >= b)
return int(a);
else
return int(b);
}
int main()
{
char a, b;
cout << "Enter first character: ";
cin >> a;
cout << "Enter second character: ";
cin >> b;
cout << "Result value = " << getHigherValue(a, b);
}
Comments
Leave a comment