7 Replies - 5958 Views - Last Post: 28 February 2011 - 10:47 PM Rate Topic: -----

#1 eze123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 11

How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:08 PM

I'm taking a intro class in a c++ class and i have been skiping class because honestly it's the type of stuff that if you see some one do it you pretty much got it down... but i'm stuck since i haven't been in class in a whiel and we have a major preogram to built and i can't remember how to end a program if an invalid input is entered help?
Is This A Good Question/Topic? 0
  • +

Replies To: How to stop C++ program if an invalid input is entered?

#2 RLB31384  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 97
  • Joined: 29-January 10

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:17 PM

View Posteze123, on 28 February 2011 - 10:08 PM, said:

I'm taking a intro class in a c++ class and i have been skiping class because honestly it's the type of stuff that if you see some one do it you pretty much got it down... but i'm stuck since i haven't been in class in a whiel and we have a major preogram to built and i can't remember how to end a program if an invalid input is entered help?


So you skip class because the stuff is so easy that you seen it once and you have it down. Yet you don't know it, because you haven't been to class in awhile? You could probably use a while loop
Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:19 PM

View Posteze123, on 01 March 2011 - 12:08 AM, said:

if you see some one do it you pretty much got it down


I guess that pretty much blows a hole in this theory.
Was This Post Helpful? 1
  • +
  • -

#4 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:25 PM

If you just want to kill the program, maybe assert is what you're looking for.
Was This Post Helpful? 1
  • +
  • -

#5 eze123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 11

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:26 PM

LOL omg i know it... I just can't remember right now... I'm really tired if i slept by tomorrow morning i would remember.... SORRY for asking for help i just thought that that's what this forum was for...
Was This Post Helpful? 0
  • +
  • -

#6 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:36 PM

Look at the example for assert in the link I posted. You have to form some logical expression that will evaluate to true if the input is valid and false otherwise. If false, assert fails and the program terminates.
Was This Post Helpful? 1
  • +
  • -

#7 eze123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 11

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:42 PM

Thank you I'm new to this site is there some kind of way i can boost your rep or what ever? and do i close this post?
Was This Post Helpful? 0
  • +
  • -

#8 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: How to stop C++ program if an invalid input is entered?

Posted 28 February 2011 - 10:47 PM

In the lower right corner? Click your appreciation ...
Assert is usually just a debug temporary way to handle bad data input ...
You might like to see ...
http://developers-heaven.net/forum/index.php/topic,2019.0.html

to see one simple way to test for/validate (numeric) input ...
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1