Thread: Compile Errors in my Code. Can anyone help?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Question Compile Errors in my Code. Can anyone help?

    Hi! I'm currently taking computer science one and I am very confused. I have to write a program with several different modules and I believe that I have the structure of the code right, but I keep getting the same compile errors over and over again. So, if anyone would be willing to help me figure out what the compile errors are i would greatly appreciate it.

    The errors I continuously get are that there is a syntax error before the word "sum".
    And that in the function display "num1" and "num2" are undeclared.

    I'm sorry if this seems very simple, I'm just very new at this and don't really understand a lot of what I'm doing. I would really appreciate any tips/advice/assistance that could be offered.
    Thanks!

    Here is my code:
    Code:
    #include <stdio.h>
     
    void getinput (int* pnum1, int* pnum2);
    int calc (int num1, int num2);
    void calcintops (int num1, int num2);
    void doubleops (int num1, int num2);
    int division (int num1, int num2);
    void display (int num1, int num2, sum, quotient, remainder, half_num1,
    half_num2, fraction, division);
         
    int main (void)
    {
         int num1,num2;
         int sum;
         double half_num1, half_num2;
         int quotient;
         int remainder;
         double fraction;
         int algebra;
         
         return 0;
    }
    void getInput (int* pnum1, int* pnum2)
    {
         printf("\nName: Lauryn Philpot\n\n");
         printf("\nPlease enter two integers, num1 and num2: ");
         scanf("%d%d, pnum1, pnum2");
    }
         
        
    void calcintops (int num1, int num2)
    {
         int sum;
         int quotient;
         int remainder;
    
         sum = num1 + num2;
         quotient= num1 / num2;  
         remainder = num1 % num2;
      
    }
         
    void doubleops (int num1, int num2)
    {     
         double half_num1;
         double half_num2;
         double fraction;
         
         half_num1 = (double)num1 / 2;
         half_num2 = (double)num2 / 2;
         fraction = (double)num1 / (double)num2;
         
    }
     
    int division (int num1, int num2)
    {
         int division;
     
         division = 2*num1 + 4*num2 + num1*num2 - num1 / num2;
         
    }
         
    void display (int num1, int num2, sum, quotient, remainder, half_num1,
    half_num2, fraction, division)
    {
       printf("\n%20s%20d", "The value of num1 is %d", num1);
       printf("\n%20s%20d", "The value of num2 is %d", num2);
       printf("\n%20s%20d", "The sum is %d + %d", num1, num2);
       printf("\n%20s%20f", "The half value is %d / 2", num1);
       printf("\n%20s%20f", "The half value is 2 * %d / 2", num2);
       printf("\n%20s%20d", "The quotient is 2 * %d / %d", num1, num2);
       printf("\n%20s%20d", "The remainder is %d % %d", num1, num2);
       printf("\n%20s%20f", "The fraction value is 2 * %d / 2 * %d ", num1, num2);
       printf("\n20s%20s",  "The value of divisions is ", num1, num2); 
       printf("\n\n");
    
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    #include <stdio.h>
     
    void getinput (int* pnum1, int* pnum2);
    int calc (int num1, int num2);
    void calcintops (int num1, int num2);
    void doubleops (int num1, int num2);
    int division (int num1, int num2);
    // This doesn't work. Each argument must have a type.
    void display (int num1, int num2, sum, quotient, remainder, half_num1,
    half_num2, fraction, division);
         
    int main (void)
    {
         // All unreferenced variables (ie not used anywhere). I assume you're going to use them when writing some more code later?
         int num1,num2;
         int sum;
         double half_num1, half_num2;
         int quotient;
         int remainder;
         double fraction;
         int algebra;     
         return 0;
    }
    void getInput (int* pnum1, int* pnum2)
    {
         printf("\nName: Lauryn Philpot\n\n");
         printf("\nPlease enter two integers, num1 and num2: ");
         // This doesn't work. Arguments passed to scanf must be outsides the quotes ("").
         scanf("&#37;d%d, pnum1, pnum2");
    }
         
        
    void calcintops (int num1, int num2)
    {
         int sum;
         int quotient;
         int remainder;
    
         sum = num1 + num2;
         quotient= num1 / num2;  
         remainder = num1 % num2;
         // You never return anything and the arguments aren't pointers, so the function is kindof pointless?
    }
         
    void doubleops (int num1, int num2)
    {     
         double half_num1;
         double half_num2;
         double fraction;
         
         half_num1 = (double)num1 / 2;
         half_num2 = (double)num2 / 2;
         fraction = (double)num1 / (double)num2;
         // You never return anything and the arguments aren't pointers, so the function is kindof pointless?
    
    }
     
    int division (int num1, int num2)
    {
         // You can't name a variable with the same name as the function!
         int division;
     
         division = 2*num1 + 4*num2 + num1*num2 - num1 / num2;
         // You never return anything and the arguments aren't pointers, so the function is kindof pointless?     
    }
         
    void display (int num1, int num2, sum, quotient, remainder, half_num1,
    half_num2, fraction, division)
    {
         // These are all wrong. I suggest you read up on printf again.
       printf("\n%20s%20d", "The value of num1 is %d", num1);
       printf("\n%20s%20d", "The value of num2 is %d", num2);
       printf("\n%20s%20d", "The sum is %d + %d", num1, num2);
       printf("\n%20s%20f", "The half value is %d / 2", num1);
       printf("\n%20s%20f", "The half value is 2 * %d / 2", num2);
       printf("\n%20s%20d", "The quotient is 2 * %d / %d", num1, num2);
       printf("\n%20s%20d", "The remainder is %d % %d", num1, num2);
       printf("\n%20s%20f", "The fraction value is 2 * %d / 2 * %d ", num1, num2);
       printf("\n20s%20s",  "The value of divisions is ", num1, num2); 
       printf("\n\n");
    
    }
    See comments in red.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 01:45 PM
  2. Can you create, edit and compile C code with a C++ IDE?
    By nerdpirate in forum C Programming
    Replies: 4
    Last Post: 05-31-2008, 01:54 AM
  3. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  4. compile time errors!!!!
    By devour89 in forum C++ Programming
    Replies: 6
    Last Post: 11-18-2002, 05:02 PM
  5. Compile Errors ...
    By ginoitalo in forum C++ Programming
    Replies: 1
    Last Post: 12-31-2001, 02:22 AM