Thread: module definition file

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4

    Unhappy module definition file

    In the given code there is no syntax error but still not executable, showing "linker: module definition file" as default.Plz help me out.

    Code:
    #include<stdio.h>
    int n;
    float Moment=0, Weight=0;
    float lcg;
    void main()
    {
      struct ship_tank
      {
    	  float weight;
    	  float LCG;
      };
    
    	struct ship_tank A[20];
    	int i;
    
     for(i=1;i<=n;i++)
    {
     printf("Enter the numbers of tanks:  ");
     scanf("%d",&i);
     printf("Enter the weight of tank%d:  " );
     scanf("%f",& A[i].weight);
     printf("Enter the LCG of tank%d:  ");
     scanf("%f",& A[i].LCG);
     Moment= Moment + A[i].weight*A[i].LCG;
     Weight= Weight + A[i].weight;
     lcg = Moment/Weight;
     printf(" The lcg is: %f", lcg);
     }
     }
    Last edited by Salem; 06-01-2009 at 10:45 PM. Reason: [CODE][/CODE] go AROUND the code

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please properly indent your code and post your code within [code][/code] bbcode tags. You might also want to tell us what compiler you are using, how you are using it, and post the exact error message.

    Other things to note:
    • You should declare the main function as returning an int, not void.
    • You should avoid global variables; place them in the main function instead.
    • The definition of struct ship_tank should be moved to before the main function, though it does not matter in this case. (The declaration of the array of struct ship_tank objects should remain in the main function.)
    • You use the variable n without initialising it. Nonetheless, since it is currently a global variable, it is automatically initialised to 0, but that is probably not what you want.
    • Valid array indices are from 0 to one less than the number of elements of the array, but your loop starts looping from 1 instead of 0.
    • You forgot to provide the arguments to be printed when using printf().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4
    I am using Tubo C++ compiler.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4
    Enter the number of tank: (suppose I put 'n' number of tank)
    Enter the weight of tank-1:
    Enter the LCG of tank-1:

    Enter the weight of tank-2:
    Enter the LCG of tank-2:

    The function comes out of loop when number of tank = n

    lcg = (Weight-1*LCG-1 + Weight-2*LCG-2)/(Weight-1 + weight-2)

    Printf("the lcg is: %f",lcg)

  5. #5
    Registered User
    Join Date
    Apr 2009
    Location
    Russia
    Posts
    116
    Quote Originally Posted by Sajal
    The function comes out of loop when number of tank = n
    Code:
        struct ship_tank A[20];
        int i;
    
        for (i = 1;i <= n; i++) {
            printf("Enter the numbers of tanks: ");
            scanf("%d", &i);
            ...
        }
    change it to

    Code:
        struct ship_tank A[20];
        int i;
    
        printf("Enter the numbers of tanks: ");
        fflush(stdout);
        if (scanf("\t%d\t", &n) != 1)
            return 1;
    
        for (i = 0; i < n; i++) {
            ...
        }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Function basics
    By sjleonard in forum C++ Programming
    Replies: 15
    Last Post: 11-21-2001, 12:02 PM