Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Vibhor16 Group Title

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.

  • 2 years ago
  • 2 years ago

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

    You could also mod 10 the ascii value.

    • 2 years ago
  3. agdgdgdgwngo Group Title
    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

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

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

    • 2 years ago
    • Attachments:

See more questions >>>

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.