I have a program that takes a string. Using the check() function that calculate the sum of all the value in the string of integers, I make additional computations, aka ss. The issue comes when I try to convert ss, which is an int, into a char, c. When I try to print out the newly converted value, nothing prints out on the console, not even an error message.
I have tried using static_cast<char>(ss), and it won't work. Yet when I try to print out the ss value, I get it to print it out.
Source Code
void sum(string input) { int s = check(input); int ss = (s * 9) % 10; char c = ss; cout << "val is: " << c << endl; } int main() { string x = "7992739871"; sum(x); return 0; } Can someone explain what I might be doing wrong and how it can be fixed?
charand you will get the symbol encoded for the number provided. If the number provided has no visible symbol, you print nothing you can see. Why do you want to print a number as a character?% 10code will ensure thatcwill be a non-printable/non-visible character.