Answer to Question #305892 in C++ for Magisk

Question #305892

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;


}

1
Expert's answer
2022-03-04T06:31:53-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog