Hello, I have to make a program that takes in a 2 character & out puts their eqivalent in ASCII Decimals.
For example; input = j b , output = 106 98 (ie, j= 106 in ASCII table, b= 98)
eg 2; input = J B , output = 74 66
so as you can see, an uppercase A has a different value than a lowercase a.
What is the most efficient way to do this?
I thought the best way would be:
1st to check whether the character is uppercase or lower case ( is there a way to do that?)
2nd use a for loop to calculate the decimal of the character
#include <iostream>
using namespace std;
int main()
{
char ch1 = 'a', ch2 = 'a'; // ch1 is used for the first letter of the first name
// ch2 is used for the first letter of the surname
int n1 = 97, n2 = 97, n3, n4, n5;
cout << "Enter your first name and surname: " << flush;
cin >> ch1; // read the first letter of the first name
cin.ignore(100, ' '); // ignore the rest characters in the first name
cin >> ch2; // read the first letter of the surname
for (char i = 'a'; i != ch1; i ++) {
n1 ++;
}
cout << ch1 << " " << n1 << endl;
for (char j = 'a'; j != ch2; j ++) {
n2 ++;
}
cout << ch2 << " " << n2 << endl;
return 0;
}
I dont want to create another 2 variables & 2 more for loops for if the character is uppercase because I think there may be a simpler / more efficient way to do it. Do you know of one?