A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 3 years ago
I want to convert a char to int like '7' to 7 (in C++) but every time I try it gives me its ASCII value. Basically I just want to multiply two characters like '7' * '7' = 49.
 3 years ago
I want to convert a char to int like '7' to 7 (in C++) but every time I try it gives me its ASCII value. Basically I just want to multiply two characters like '7' * '7' = 49.

This Question is Closed

jagatuba
 3 years ago
Best ResponseYou've already chosen the best response.1I solved a similar problem to this in Java by subtracting the appropriate amount from the ascii value. So numerals 09 ascii values are 3039, so simply subtract 30 from your ascii value and assign it to the variable that you want. Pseudo code: Print "Enter a number: " Input numString Parse numString to numAscii numInt=numAscii30 numInt=numInt*7 Print numInt

jagatuba
 3 years ago
Best ResponseYou've already chosen the best response.1You could also mod 10 the ascii value.

agdgdgdgwngo
 3 years ago
Best ResponseYou've already chosen the best response.2for the '0' to '9' ASCII characters, just subtract '0' (the character) from it, because character literals in C (and i think C++ as well) are just integer values of their ASCII encoding. for example: http://ideone.com/noXGk

jagatuba
 3 years ago
Best ResponseYou've already chosen the best response.1Thanks agdg. I knew you'd pipe in with something useful.
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.