Thread: Assignment output help

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    127

    Assignment output help

    When I submit my assignment I come back with the following errors, I'm not sure what I need to change to make it pass the tests, I think it might be because the tests are seperate but I'm not completely sure so any help would be appreciated.
    Checking that submission compiles
    Submission compiles correctly

    Run tests
    starting test 1 ... completed
    starting test 2 ... completed
    starting test 3 ...

    These lines differ at the point marked below
    ==>Enter barcode : - Invalid barcode
    ==>Enter barcode : 9 300605 013728 - Invalid barcode
    ^

    TEST FAILURE

    Test command : cat /home/rheise/dspp/test3.dat | ./a.out

    Your test result

    Enter barcode : 9 300605 013728 - Invalid barcode

    Enter barcode : - Invalid barcode

    Enter barcode : 9 300605 013728 - Invalid barcode

    Enter barcode : - Invalid barcode

    Enter barcode : 9_300605_013728 - Invalid barcode

    Enter barcode : 9310720020105 - Invalid barcode

    Enter barcode : 9 310720 020l05 - Invalid barcode

    Enter barcode : 9 300605 013728 - Valid barcode

    Enter barcode : 123 456 - Invalid barcode

    Enter barcode :
    Expected result
    Enter barcode : 9 300605 013728 - Invalid barcode

    Enter barcode : 9 300605 013728 - Invalid barcode

    Enter barcode : 9_300605_013728 - Invalid barcode

    Enter barcode : 9310720020105 - Invalid barcode

    Enter barcode : 9 310720 020l05 - Invalid barcode

    Enter barcode : 9 300605 013728 - Valid barcode

    Enter barcode : 123 456 - Invalid barcode

    Enter barcode :
    completed
    starting test 4 ...

    These lines differ at the point marked below
    ==>Enter barcode : ihfdsfdsndsvljfd - Invalid barcode
    ==>Enter barcode : 9 310720 020105 - Valid barcode
    ^

    TEST FAILURE

    Test command : cat /home/rheise/dspp/test4.dat | ./a.out

    Your test result

    Enter barcode : fddsfhdsfweqrfds - Invalid barcode

    Enter barcode : ihfdsfdsndsvljfd - Invalid barcode

    Enter barcode : spln;o;lvdkmfdsp - Invalid barcode

    Enter barcode : o - Invalid barcode

    Enter barcode : 9 310720 020105 - Valid barcode

    Enter barcode :
    Expected result
    Enter barcode : fddsfhdsfweqrfds - Invalid barcode

    Enter barcode : 9 310720 020105 - Valid barcode

    Enter barcode :
    completed

    Test score = 4 out of 8
    Make sure your output EXACTLY matches the expected output

    Run code feedback programs

    45. if ((index!=1) && (index!=8) && ((barcode[index]<'0') || (barcode[index] > '9')))
    ==> The previous line is greater than 80 characters in length

    The previous lines in assign1.c are unacceptable

    ==> Your main function contains a loop construct.
    In this subject, loops in the main function are not
    allowed in order to promote better top-down design.

    ==> Your main function contains a scanf call.
    In this subject, scanf in the main function is not
    allowed in order to promote better top-down design.

    int main()
    {

    ==> This function has over 60 lines.
    You need to split it into smaller functions
    ==> Your program only contains the main function
    Your program must be split into appropriate functions.

    ==> At least one function in your code must use 'call by reference'.
    You do not appear to have done this in your program.

    The previous lines in assign1.c are unacceptable
    Code:
    changing thanks.
    Thanks
    Last edited by Taka; 09-23-2006 at 08:12 AM.

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I don't really see what your question is. The output from the tests even tells you what is wrong. How about trying to fix that ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    Quote Originally Posted by Happy_Reaper
    I don't really see what your question is. The output from the tests even tells you what is wrong. How about trying to fix that ?
    I know whats wrong, but I'm having trouble fixing it. Thats the problem. I've tried a few different things, changing the code and such but I can't seem to get it to run properlly.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm not sure what I need to change to make it pass the tests
    Neither am I. Perhaps if you also posted the requirements of the program so that we know what a valid barcode is? The expected result for some of the same barcodes seem to be both valid and invalid. That makes debugging your code exceptionally difficult.

    The test also seems overly vicious. You fail if there's a scanf call in main? I can understand that, but not for the reason of promoting top-down design. A loop isn't allowed in main? That sounds like some bozo wants you to over modularize, which is almost as bad as not modularizing at all.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    You are to prepare a C program which reads in a barcode, validates it is in the correct format and then calculates the sum described above. The barcode should have the format of - 1 123456 123456 Note the spaces between the sets of digits. The program should then print out the code entered with a further message on the same line saying whether the code is correct or wrong. The program should then accept another barcode. The program terminates when a code of all zeroes is entered, without testing the code (which is, of course, correct).
    Thanks for taking a look for me.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >The barcode should have the format of - 1 123456 123456 Note the spaces between the sets of digits.
    Okay, then explain the ambiguity in the test's expected result:
    Code:
    Expected result
    Enter barcode : 9 300605 013728 - Invalid barcode
    
    Enter barcode : 9 300605 013728 - Invalid barcode
    
    Enter barcode : 9_300605_013728 - Invalid barcode
    
    Enter barcode : 9310720020105 - Invalid barcode
    
    Enter barcode : 9 310720 020l05 - Invalid barcode
    
    Enter barcode : 9 300605 013728 - Valid barcode
    
    Enter barcode : 123 456 - Invalid barcode
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    Yeah I don't know, thats what I don't understand... I'll have a look at it again... Thanks for trying though.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Yeah I don't know, thats what I don't understand...
    It's possible that the test program is broken, but a better reaction is to believe you don't understand the program well enough. And I don't mean the program you wrote, I mean the program you're expected to write. Your first task should be to get as much clarification as necessary to fully understand what you need to do.
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Taka, your problems with this program appear to be easy to fix, but we can't fix much of anything, without seeing the program.

    Some of the basic program functions will have to be changed to meet the requirements of your assignment. A tiny tweak here and there just won't do it.

    Why don't you make a concise list of the problems that were noted, post up some code for the relevant parts, and let's see what looks good to solve it.

    Something like this:

    1) Main needs to be broken up into more functions
    2) A pass by reference (in effect) needs to be added
    3) Accuracy of bar code's needs work.

    Pasting up a HUGE output log with all kinds of info we know nothing about, is a waste of our time. We need relevant code and specific requirements of the assignment. If you want just pseudocode or descriptive idea's, (but no code), tell us.

    Adak

  10. #10
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    Sorry Adak I did have the code there but I took it down while I worked on it so i wouldn't get confused when I came back.

    So this is the original code:
    Code:
    working on it now
    Sorry I'm only learning this so there are probably a tonne of obvious mistakes or something...
    Last edited by Taka; 09-23-2006 at 11:43 PM.

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    These are not function calls, they are prototypes. If I had to guess your compiler ignored your attempts to call functions and just returned 0 for main. You need to move these.
    Code:
    int main()
    {
    
       void length();
       void calculations(char barcode[], int index);
       void valid(int index, char barcode[]);
    
       return 0;
    }
    Everything else looks fine to me at a glance. More debugging steps will have to be taken later as you test the program.
    Code:
    if ((index!=1) && (index!=8) && ((barcode[index]<'0') || (barcode[index] > '9')))
    I'm curious if your allowed to use isdigit() in your program. You could replace some of this stuff.

    I also remember reading that you're not allowed to use scanf() in this program, so work on the alternatives. You could use the usual fgets() + sscanf() perhaps? or strtol()?

  12. #12
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    Hmmm ok, sorry but I'm not really sure where I would move them? Any hints?

    I'm not that confident with fgets() and haven't learnt the others yet so I'd prefer to stick with scanf().

    Thanks.

  13. #13
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Most of the time, people move them into a header file, but don't do that until you learn how in class. Just put them before the main() function.

    fgets really isn't that hard to use. Like I said, work on it. There are many, many sources to consider.

  14. #14
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    Thanks for the links and your help (",)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange virtual function output
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2008, 08:08 AM
  2. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  3. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM