Thread: End of user input must be 999

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Malaysia, Cyberjaya
    Posts
    38

    Question End of user input must be 999

    hey there.. need ur guys help here..
    ok.. let me give u guys my question so that it will be clearer for u to help me.. =)

    "Your program will prompt the userto enter a series of number and the last value
    read is sentinel 999.(i.e to end input, the user must enter 999 as the last value"

    how am i going to do this?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You will prompt the user to enter a series of numbers. You will then read numbers until a 999 is read.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by naspek View Post
    hey there.. need ur guys help here..
    ok.. let me give u guys my question so that it will be clearer for u to help me.. =)

    "Your program will prompt the userto enter a series of number and the last value
    read is sentinel 999.(i.e to end input, the user must enter 999 as the last value"

    how am i going to do this?
    Use scanf to read integers until you read 999.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It is very simple...
    It means all you do is write some pseudo code on how you would do this logically, then translate it into code.
    No tricky C stuff or anything.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Location
    Malaysia, Cyberjaya
    Posts
    38
    Quote Originally Posted by BEN10 View Post
    Use scanf to read integers until you read 999.
    ok... i dont know how to use scanf to read the integers..
    actually.. this is just part of the full code.. but, i just cant figure out, how to solve this problem..
    it may look simple for an experience programmer, but, for newbie like me,
    it's kinda hard..
    please please please give me an example.. =)

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    scanf("%d", &myvar);
    You can look at the documentation for scanf what parameters it accepts and what they mean.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by naspek View Post
    ok... i dont know how to use scanf to read the integers..
    actually.. this is just part of the full code.. but, i just cant figure out, how to solve this problem..
    it may look simple for an experience programmer, but, for newbie like me,
    it's kinda hard..
    please please please give me an example.. =)
    Here's an example.
    Code:
    int i;
    printf("Enter i");
    scanf("%d",&i);
    Actually to read a list of numbers until 999, you will have to use a loop with the condition being num!=999.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to tell them how to do things logically. A programmer must be able to figure that out him-/herself.
    Using loops and placing code in right positions are not solutions we should hand out.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Elysia View Post
    You don't need to tell them how to do things logically. A programmer must be able to figure that out him-/herself.
    Using loops and placing code in right positions are not solutions we should hand out.
    Actually my aim was to tell the OP that if he/she doesn't know how to use scanf, then it might be difficult to do this problem.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Really? Then what was the purpose of the last bit?
    Quote Originally Posted by BEN10 View Post
    Actually to read a list of numbers until 999, you will have to use a loop with the condition being num!=999.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jul 2009
    Location
    Malaysia, Cyberjaya
    Posts
    38

    i still can't get it..

    ok.. the program suppose to be like this..

    Enter temperature readings in Fahrenheit (999 to end): 80 90 85
    75 70 999


    i dont know how to do the 999 at the last of the sentence..

  12. #12
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Well, I'm assuming you've got the first part done since your posting it.
    So, That means that you are reading in input and storing it somewhere right ?
    So, all you have to do is think of a way to not read in more data if the user entered 999.
    Try writing it in english and then work your way into code.

    heres a simple example -

    Ask the user for input.
    Check the input.
    If it is not 999, store it.
    otherwise
    stop asking for input.
    Last edited by Spidey; 07-15-2009 at 03:55 AM.

  13. #13
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Elysia View Post
    Really? Then what was the purpose of the last bit?
    Again I got misunderstood. Seriously I wasn't in a mood to provide the OP the solution to his/her query. Ok, now from the next time I'll be more cautious while posting.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Alright, no worries.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    BEN10 - picture Elysia as a "watch hound" and what you did was equivalent to passing a note off during an exam!

    She busted me once...or twice. No worries.

    What would really get me is if the same OP, continued to post the same problem if after giving such guidance on how to write the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with error checking on input from user.
    By NuNn in forum C Programming
    Replies: 8
    Last Post: 01-23-2009, 12:59 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 07:25 PM
  4. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 10:53 AM
  5. Ending user input with # character
    By jowatkins in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2004, 10:41 AM