1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I need help on this c++ problem pls

  1. Jul 20, 2006 #1
    how can i make a student identification number to be a four digit integer and when you type 0 for the identification number it will terminates. thanks
  2. jcsd
  3. Jul 20, 2006 #2
    use an unsigned integer. when the id equals 0 break; or use a while loop.
  4. Jul 21, 2006 #3
    while (idnum=4)
    printf("Input ID number");
    scanf("%d", &idnum);

    if (idnum = 0)
    printf("ID number %d", idnum);

    any correction from my while statement coz i cant get the exact 4 digit integer for the id number thanks in advance for your help
    Last edited: Jul 21, 2006
  5. Jul 21, 2006 #4


    User Avatar

    Staff: Mentor

    You shouldn't need a loop for this. Just read an integer and test it with an if-statement to see if it's in the proper range. What are the largest and smallest possible values for a four-digit ID number?
  6. Jul 21, 2006 #5
    ok thanks jt ill try to work on it
  7. Jul 21, 2006 #6
    oh i thought you wanted to keep taking in ID# untill 0...other wise there's no point in using the word "termination". In the while loop do you know which equals sign to use? You want the comparative/relational operator. same with teh if statement. My bad you just want it within a range. ya what jtbell said is correct
  8. Jul 21, 2006 #7
    my problem states that "student identification numbers are four-digit integers. input should terminate when i type 0 for the student identification number" sorry guys im having a hard time wth the problem need help..
  9. Jul 21, 2006 #8
    Well there are two scenarios from the posed question.

    [0] That you need only to accept 1 ID and check that it is within range
    [1] That you keep accepting IDs within range until 0 is inputted.(thus a loop)
    the sentence "input should terminate when i type 0" to me would imply the second scenario for loop. Perhaps you should ask your professor(i'm guessing this is a homework problem) to clarify
  10. Jul 21, 2006 #9


    User Avatar

    Staff: Mentor

    Yeah, I was focusing on the four-digit integer requirement and your first guess at a solution which looked like you were trying to read four digits, one digit at a time.

    If you've been studying loops in class just now, then neurocomp2003's scenario [2] is probably what you want. But if that doesn't clearly agree with the full statement of the assignment, then you should definitely ask your instructor.
  11. Jul 21, 2006 #10
    to jt and neo thanks guys for the help...im almost near with solution...actually its my midterm exam. its the only one that i left unsolved the rest are doin fine...best regards to both of you guys...
  12. Jul 21, 2006 #11


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    BE VERY CAREFUL with your equals signs in if and while statements. The following if statement:

    if (idnum = 0)

    WILL NOT WORK. The single '=' means assignment; the result of this statement is that idnum is actually assigned the value 0, not compared with 0. The if statement will never run, because 0 means false.

    What you want, instead, is the '==' operator, which means comparison:

    if (idnum == 0)

    - Warren
  13. Jul 21, 2006 #12


    User Avatar

    Staff: Mentor

    Are you allowed to use outside assistance on exams?
  14. Jul 21, 2006 #13
  15. Jul 23, 2006 #14
    the admin can close the thread. problem already been solved thanks for the help guys...
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: I need help on this c++ problem pls
  1. Help with C++ problem (Replies: 7)