Thread: Need help with this c program about linked list

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    Need help with this c program about linked list

    I had done the coding but I don't where is the error bcz there is a error in the program.The program shows error when compiling.plz help me.i'm using visual c++ 6.0 compiler between.i using c language.thanx in advance for helping.

    Write a program that inserts 25 random integers from 0 to 100 in order in a linked list. The program should calculate the sum of the elements and the floating-point average of the elements. (8 marks)

    Sample output:

    The list is:
    6 12 14 20 27 31 31 34 37 38 56 59 63 66 72 73 73 76 77 79 88 94 95 96 97 *

    The sum is 1414

    The average is 56.56





    my coding:


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    typedef struct Listnode {
    int data;
    struct Listnode *nextPtr;
    }ListNode;
    
    typedef ListNode *ListNodePtr;
    
    
    int sumList(ListNodePtr a);
    double averageList(ListNodePtr a);
    void insert(ListNodePtr *sPtr, int value);
    void printList(ListNodePtr currentPtr);
    
    int main(void)
    {
    
    
    srand(time( NULL));
    
    for (i=1;<=25; i++) {
    insert(rand() %101);
    )
    
    printf("The list is:\n");
    printf("The sum is %d\n");
    printf("The average is%f\n");
    
    return 0;
    
    }
    
    
    int sumList(ListNodePtr a)
    {
    
    while ( currentPtr !=NULL) {
    
    total +=currentPtr->data;
    
    }
    
    double averageList(ListNodePtr a)
    {
    
    while (currentPtr !=NULL){
    ++count;
    total += currentPtr->data;
    
    }
    return total / count;
    }
    
    void insert(ListNodePtr *sPtr, int value)
    {
    
    }
    void printList(ListNodePtr currentPtr)
    {
    
    
    }

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    error 1:in main() variable 'i' is undefined.define it as
    Code:
    int i
    error 2:insert function should take 2 arguments while calling it.
    Code:
    insert(rand() %101);
    error 3:change the closing brace here
    Code:
    for (i=1;<=25; i++) {
    insert(rand() %101);
    }
    these are the basic errors that can be corrected at compile time.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Okay you're new here. Welcome to the board.
    Please note that your target audience of people who can actually help you include amoung others, many professional software developers, who like myself will tend to simply ignore those that write as though they're texting a seven year old.
    Unless a seven year old is who you expect to be helping you, I suggest you don't use things like bcz, plz and thanx here. Also, make sure you use propper capitalisation. I've seen a lot worse than this, but I'll give you the heads-up right from the get-go.
    Not trying to be harsh, just want to be clear on this for your own bennefit.

    The best thing you can do with that code is to start the practice of indenting. Each line after an open-curly-brace should start with one more tab than the previous line. Each line after a close-curly-brace then starts with one less tab. This makes it vey easy to spot things like the start and end of a function, or the start and end of a control block, such as the end of a while loop. Doing this now will make one of your errors obvious.

    Another important tip is that if your compilers gives errors, don't just tell us about them, actually copy the first few of them and paste those here. People are more likely to help if they can fix your bugs without having to create a new project, copy the code across and compile it just to have the errors pointed out.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  2. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 01:13 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM