Thread: total newbie

  1. #16
    Citizen of Awesometown the_jackass's Avatar
    Join Date
    Oct 2014
    Location
    Awesometown
    Posts
    269
    ok now payment time. can u get someone to notice this thread: Command line argument parsing issues?

  2. #17
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Actually, I don't think you have it correct, unless you have a newer version of the program that you didn't show. Your input is
    Code:
    54752 2.64
    53247 2.87
    52247 2.20
    57412 2.78
    59321 2.58
    49665 2.86
    52001 2.55
    Your output is
    Code:
    dprev = 54752, pprev = 2.640000
    d = 52247,p = 2.200000
    The efficiency is -0.287000
    d = 59321,p = 2.580000
    The efficiency is 0.145626
    d = 52001,p = 2.550000
    The efficiency is 0.122432
    You have 7 lines of input, you should see 6 iterations of the loop (you the first line before the loop, then read the next 6 lines in the looip).

    As Matticus and I pointed out, you need to read into d and p once per loop iteration. Maybe I wasn't clear enough, but you only need the scanf in the loop condition itself. Like so:
    Code:
    while (scanf == 2)
        maybe print values
        calculate efficiency
        update dprev and pprev
    Correct output should look like this (I added a line to print dprev and pprev inside the loop, just to check):
    Code:
     dprev = 54752, pprev = 2.640000
    d = 53247,p = 2.870000
     dprev = 54752, pprev = 2.640000
    The efficiency is -0.175415
    d = 52247,p = 2.200000
     dprev = 53247, pprev = 2.870000
    The efficiency is -0.287000
    d = 57412,p = 2.780000
     dprev = 52247, pprev = 2.200000
    The efficiency is 0.042594
    d = 59321,p = 2.580000
     dprev = 57412, pprev = 2.780000
    The efficiency is 0.145626
    d = 49665,p = 2.860000
     dprev = 59321, pprev = 2.580000
    The efficiency is -0.026719
    d = 52001,p = 2.550000
     dprev = 49665, pprev = 2.860000
    The efficiency is 0.122432
    Also, I told you to check the first scanf, the one above the loop, to make sure it read properly. If it didn't, you could get stuck in an infinite loop or encounter other problems.

    And, you're not checking d-dprev to ensure it's non-zero before you try to divide -- this can be very bad, it can crash your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Total Newbie (FNG)....
    By Bustsofa69 in forum C Programming
    Replies: 9
    Last Post: 03-07-2014, 11:05 PM
  2. Total newbie question
    By 20,000leeks in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2006, 07:58 PM
  3. Total Newbie Question
    By Kid A in forum C++ Programming
    Replies: 4
    Last Post: 06-22-2006, 05:36 AM
  4. Total newbie to programming C! Need help...
    By majortony in forum C Programming
    Replies: 3
    Last Post: 11-17-2005, 07:51 AM
  5. Total Newbie Here
    By Wiser in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-14-2003, 10:31 PM