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. Type checking

Type checking

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
2 Posts 2 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.
  • R Offline
    R Offline
    Rahul Thengadi
    wrote on last edited by
    #1

    How to track for char as input while doing addition for integers. If accidentally given char as input how to prevent it from performing addition calculation.

    L 1 Reply Last reply
    0
    • R Rahul Thengadi

      How to track for char as input while doing addition for integers. If accidentally given char as input how to prevent it from performing addition calculation.

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      You can either 1.) Scan each character of the entry before doing anything with it, this is the generic form of a parser. 2.) Try converting it and if you get an error prompt, reloop and ask for entry again. 3.) Look for an error and if found exit program with error notification. Which depends on what the source of the number is and what your goals with your program are. For example if the source of the number is a file not much use prompting and asking for re-entry ... files can't do anything about it :-) So the question comes down as, in the program you are writing what do you think it should do? What is the most elegant and most useful?

      In vino veritas

      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