if you have a few moments.......

This is a discussion on if you have a few moments....... within the C Programming forums, part of the General Programming Boards category; I have attached a program (unfinished) I have a problem in the second case that I can't fix. I tried ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    28

    if you have a few moments.......

    I have attached a program (unfinished)
    I have a problem in the second case that I can't fix.
    I tried everything I know.
    I think the problem is it can't receive the right info even thoug it should.

    can any one help me please?
    Attached Files Attached Files

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > gets(Date);

    Don't you mean 'date'? There is no 'Date' in your program.
    Also, NEVER use gets. Use fgets instead.

    > while(choice!='9')

    You use 'choice' uninitialized here. This is bad. Initialize it first.

    Other than that, I got tired of reading. Post what your program isn't doing correctly and then perhaps you'll get a bit more help.

    [edit]
    Your date check can REALLY be simplified.

    Code:
    int dpm[12] = {31,28,31,30,31,30,31,30,31,31,30,31};
    
    if( day < 1 || day > dpm[month-1] )
    {
        printf("Enter a valid day, between 1 and %d.\n", dpm[month-1]);
    }
    [/edit]

    Naturally you will want to modify slightly for leap year.

    Quzah.
    Last edited by quzah; 05-22-2002 at 05:53 PM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    50
    Also,

    Do us a favor - cause we love you so much -

    void main()

    ->

    Code:
    int main()
         {
               ....
    
               return 0;
          }

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    28
    Also,

    Do us a favor - cause we love you so much -

    void main()

    ->

    Code:
    int main()
         {
               ....
    
               return 0;
          }
    I know ,I know int main is better but we can't use in this course.
    so I'll have to keep void main. sorry.


    quzah,
    thanks for the MUCH better date check.


    QUOTE]

    Post what your program isn't doing correctly and then perhaps you'll get a bit more help.
    [/QUOTE]

    this is the part I think gets me into an endless loop but I don't know why.

    Code:
    printf("enter item's id, max 999999999\n");
    	fgets(item_id,10,stdin);
    	if(sscanf(item_id,"%d",&itemid)==1)
    	{  ...............

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    28
    I still don't know why that way is not working

    but I fixed it with an internal function instead.

    I would still like to know why this isn't working.

    *************************************
    printf("enter item's id, max 999999999\n");
    fgets(item_id,10,stdin);
    if(sscanf(item_id,"%d",&itemid)==1)
    { ...............
    *************************************
    thanks.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    printf("enter item's id, max 999999999\n"); 
    fgets(item_id,10,stdin); 
    if(sscanf(item_id,"%d",&itemid)==1) 
    {
    - 999999999 is way bigger than an int. Don't expect you program to work with numbers that big (unless you change the data types).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Saddest moments in life - your favorite ide changes
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-24-2005, 04:50 AM
  2. Funniest Film Moments
    By minesweeper in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 04-13-2002, 07:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21