Skip to main content

Thread: C++ loop problem (Not working as expected)


i keep getting slight issue, when try validate input.

code:
unsigned char response =0;   while ((response < 1) || (response > 3)) { //if validation errs enter new cin >> response; }
in theory should carry on until user inputs right item. i've changed char int , there's no difference. (not there should be)

i've tried numerous ways of writing while parameters still nothing.

here's how i've tested it.

enter enter y, enter 1 = never ending loop
enter 5 then 0 = never ending loop...

i'm going try internal if... didn't work same results.

enter letter repeats indefinitely, there way of validating natural numbers or way exclude else?

works int type

problem when type char read ascii chars instead of numbers
if statement have compare against ascii chars bei adding single quotes around numbers or subtracting '0' (the offset of numbers in ascii) input
not necessary if use int type


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] C++ loop problem (Not working as expected)


Ubuntu

Comments

Popular posts from this blog

Problem with all comment components. - Joomla! Forum - community, help and support

Nogen der kender et simpelt hvidt template med topmenu kun - Joomla! Forum - community, help and support

Perplessità: Help me please :) - Joomla! Forum - community, help and support