Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to test a type int as a char

how to test a type int as a char

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jared F
    wrote on last edited by
    #1

    I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance

    D N 2 Replies Last reply
    0
    • J Jared F

      I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      dudeoffrance wrote: if(number=='c') Which is equivalent to:

      if (number == 99)


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      1 Reply Last reply
      0
      • J Jared F

        I would like to know if there is a way to store a character in a type int variable. I would still like the variable to be able to store integers, but if a certain charcter is entered I would like the program to do something else. example: int number; cout<<"Enter a number: "; //This is where I would like to enter 'c' cin>>number; if(number=='c') { ... } else { ... } can you please help? dudeoffrance

        N Offline
        N Offline
        namaskaaram
        wrote on last edited by
        #3

        well yes u can..... character is just i byte where as and integet is four bytes..... by doing the above code.....that u have listed.....u will get the ascii value of the character...... search for the ascii table....it will give the corresponding values for a character variable..... in ur case the character 'c' has an intef=ger value of 99..... cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups