Thread: why am i getting a garbage value also i need you to criticize my program

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    why am i getting a garbage value also i need you to criticize my program

    when i input zero the program will reset how can i stop that from happenning, and when i compile my program the (Avg cost/lb) is giving me (-1.#J) what is this crap!! Also how can i improve this program to be more bullet.
    Last edited by joker_tony; 03-27-2008 at 11:07 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, run is 0, i is 0; what do you expect 0/0 to print?

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i think it should be error

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    oh yea i get it now how can i change that

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    i think it should be zero right
    Only if you have a very shaky grasp on numbers.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i dont know what to do also how come when i type in a garbage string i will read the first letter. i want it to read everything. also is tehre a way to change that

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    oh yea i get it now how can i change that
    What do you want to change? My suggestion is not to print the receipt, or whatever that is, all the time; or check to see if i is 0 and if so don't print that line.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    i dont know what to do also how come when i type in a garbage string i will read the first letter. i want it to read everything. also is tehre a way to change that
    Change what?

    scanf("%c") reads in a (single, solitary) letter; if that's not what you want, then that's what you want to change.

    Also, fflush(stdin) is undefined behavior, so there's no telling what happens after that.

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    well, i have to print that line because its an assigment

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i thnink i should change it to scanf("%s") to read the string. also maybe if i put a loop on avg it may work saying if its zero to ask to input a number again. or something like that

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can't loop on avg, since it's computed from a through h. Consider: right after you hit r, everything gets zeroed out; you don't want the user to enter a number somewhere. If this is an assignment, then your instructor (should have) gave you guidelines that should tell you what to print when the average doesn't exist.

  12. #12
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    is there any way to fix it

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    is there any way to fix it
    fix what?

  14. #14
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    fix the line of the garbage output becuase when the proffesor had compile his program his values were set to zero

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What do you mean? Do you mean he printed 0 for the average? Then check for i=0, and print 0 instead of calculating the average.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM