So im trying to subtract two ascii value by first converting the chars to its ascii and then mod but its not giving the correct ouput. I am not sure why. Thanks for any help
1 2 3 4 5 6
int shift;
char c = 'e';
char s = 't';
shift = (int(c) - int(s)) % 26;
cout << shift << endl;
Is there a way to use the mathematical mod function in c++?
1 2 3 4 5 6 7 8 9
#include <iostream>
usingnamespace std;
int mod( int x, int m ) { return x >= 0 ? x % m : mod( x + m, m ); }
int main()
{
cout << mod( 'e' - 't', 26 ) << '\n';
}