#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    3
    Rep Power
    0

    determining integer/non-integer value


    hi,
    how do i write a program which determines whether the value entered is integer or non-integer by using only control structures.
    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    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?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    3
    Rep Power
    0
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    34
    Rep Power
    13
    Basically loop through the string and if you find a character that's not '0' - '9'

    return false.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    3
    Rep Power
    0

    complete assignment


    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)

    if 'y'...
    i want to test the value for integer/nonInteger & even/odd & add to the counter accordingly....
    if 'n'
    if dispalys
    1)no. of values entered
    2)odd values entered
    3)even values entered
    4)sum
    5)average
    6)integer values entered
    7)nonInteger values entered


    here's what i have so far

    #include <iostream.h>


    void main()
    {
    int value,sum=0,average=0;
    char response;
    int valueCount=0, intCount=0, nonIntCount=0;
    int evenCount=0, oddCount=0;

    cout <<"\nDo you want to enter a value? (y/n): ";
    cin >>response;

    while ((response|32)=='y'){
    cout<<"\nEnter your Value: ";
    cin >>value;
    sum=sum+value;

    valueCount=valueCount+1;

    if (value%2==0)
    evenCount=evenCount+1;

    else oddCount=oddCount+1;

    cout<<"\nDo you want to enter a value? (y/n): ";
    cin>>response;
    }

    average=sum/valueCount;

    cout<<"\nThe number of Values you entered is: "
    <<valueCount;
    cout<<"\nThe sum of all the values you entered is: "
    <<sum;
    cout<<"\nThe average of the values you entered is: "
    <<average;
    cout<<"\nThe number of interger values you entered is: "
    <<intCount;
    cout<<"\nThe number of non-integer values you entered is: "
    <<nonIntCount;
    cout<<"\nThe number of even values you entered is: "
    <<evenCount;
    cout<<"\nThe number of odd values you entered is: "
    <<oddCount<<endl<<endl;
    }

    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

IMN logo majestic logo threadwatch logo seochat tools logo