Answer to Question #325794 in C++ for Secret Agent

Question #325794

Comparing Characters

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:

  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:
  3. Return type - int
  4. Name - getHigherValue
  5. Parameters - 2 characters to be compared
  6. Description - the ASCII value of the higher character.
  7. Hint: Comparing characters in C++ is just like comparing integers.
  8. DO NOT EDIT ANYTHING IN THE MAIN

Input


1. First character

2. Second character

Output


Enter·first·character:·a
Enter·second·character:·h
Result·value·=·104
1
Expert's answer
2022-04-08T07:57:56-0400
#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);
}

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
APPROVED BY CLIENTS