March 6th, 2002, 10:00 PM
determining integer/non-integer value
how do i write a program which determines whether the value entered is integer or non-integer by using only control structures.
March 7th, 2002, 02:39 PM
i have no idea what you mean by "control structures".
but you can determine if a string is float by testing for the "." eg....
and you can test for the int-value being "0" and it not being the string "0".
could you please post more information about your specific problem?
March 7th, 2002, 10:07 PM
sorry about being unclear....
what i wanted to do is
check the user entered value & see whether it's an integer or non-integer....
i'm allowed to use only if,for & while (control structures) & only allowed to use <iostream> or <iostream.h>
thanks for the effort
March 7th, 2002, 11:22 PM
Basically loop through the string and if you find a character that's not '0' - '9'
March 8th, 2002, 01:59 AM
maybe it'll make more sense if i explain the whole thing...
i want to constantly ask the user whether he/she wants to enter a value(y/n)
i want to test the value for integer/nonInteger & even/odd & add to the counter accordingly....
1)no. of values entered
2)odd values entered
3)even values entered
6)integer values entered
7)nonInteger values entered
here's what i have so far
int valueCount=0, intCount=0, nonIntCount=0;
int evenCount=0, oddCount=0;
cout <<"\nDo you want to enter a value? (y/n): ";
cout<<"\nEnter your Value: ";
cout<<"\nDo you want to enter a value? (y/n): ";
cout<<"\nThe number of Values you entered is: "
cout<<"\nThe sum of all the values you entered is: "
cout<<"\nThe average of the values you entered is: "
cout<<"\nThe number of interger values you entered is: "
cout<<"\nThe number of non-integer values you entered is: "
cout<<"\nThe number of even values you entered is: "
cout<<"\nThe number of odd values you entered is: "
p.s. i've been able to test the value for odd/even if it' s an integer value but changing it to float '%' doesn't seem to work
thanks for all the help