Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Vibhor16

  • 2 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
  1. jagatuba
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I solved a similar problem to this in Java by subtracting the appropriate amount from the ascii value. So numerals 0-9 ascii values are 30-39, 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=numAscii-30 numInt=numInt*7 Print numInt

  2. jagatuba
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    You could also mod 10 the ascii value.

  3. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 2

    for 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

  4. jagatuba
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Thanks agdg. I knew you'd pipe in with something useful.

  5. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.