1. In the code editor, you are provided with a main() function that asks the user for 2 characters, passes these characters to a function call of the getHigherValue() function, and then prints out the ASCII value of the higher character.
2. Your task is to implement the getHigherValue function which has the following details:
Return type - int
Name - getHigherValue
Parameters - 2 characters to be compared
Description - the ASCII value of the higher character.
3. Hint: Comparing characters in C++ is just like comparing integers.
4. DO NOT EDIT ANYTHING IN THE MAIN
Input
1. First character
2. Second character
This is the given code:
#include <iostream>
using namespace std;
int main() {
char a, b;
cout << "Enter first character: ";
cin >> a;
cout << "Enter second character: ";
cin >> b;
cout << "Result value = " << getHigherValue(a, b);
return 0;
}
#include <iostream>
using namespace std;
int getHigherValue(char a, char b)
{
int x;
x = int(a);
if(a > b) x = int(a);
if(a < b) x = int(b);
return(x);
}
int main()
{
char a, b;
cout << "Enter first character: ";
cin >> a;
cout << "Enter second character: ";
cin >> b;
cout << "Result value = " << getHigherValue(a, b);
return 0;
}
Comments
Leave a comment