In C++, how would I program an exception that catches any number over 10? -
i know sounds simple but...
i'm doing simple guessing game , i'm trying use try/throw/catch handle error of input of on 10. don't think teacher wants simple
if(x>10) { //do }
instead think wants do:
if(x>10) { throw dont_know_what_to_put ; } catch(dont_know_what_to_put) { //do }
how do throw , catch? throw , catch work exceptions , not random throws?
edit: want throw error if input on 10. catch error , output number out of range want.
and trust me, never want this, teacher's instructions unclear don't know if wants me inputs invalid using try/catch/throw or not.
if wanted impressive
#include <stdexcep> . . . . throw std:range_error ("your message here") ; . . . . try { } catch (std::exception &error) { cerr << errror.what () << endl ; }
Comments
Post a Comment