Error while writing integer calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jvan12
    New Member
    • Feb 2010
    • 2

    Error while writing integer calculator

    I am very new to writing in c on terminal for mac and I am attempting to write an integer calculator that has a quotient and remainder, this is what i have written;

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int 
    
    main(void)
    
    {
    float numerator, denominator, result;
    
    int quot;
    int rem;
    
    div_t;
    
    printf("Please enter numerator.\n");
    scanf("%f" ,&numerator);
    printf("Please enter denominator.\n");
    scanf("%f" ,&denominator);
    result=div(numerator,denominator);    
    printf("That equals %f and the remainder is %f\n", quot, rem);
    return (0);
    }
    When I try to compile I get the error reading:

    intdiv.c: In function ‘main’:
    intdiv.c:14: warning: useless type name in empty declaration
    intdiv.c:20: error: incompatible types in assignment

    What am I doing wrong and how can I fix it?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Look at line 14, what does it do?

    Look up the function div, what is the types of its parameters? What is it's return type? What are the types of your variables numerator, denominator, result?

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      If you expect your calculator to process something like 5+(7/3)*(14-9)/6 when you get done with it, you may be tackling something a bit too complicated at this time. But don`t be swayed from your objective by of a naysayer.

      Comment

      • jvan12
        New Member
        • Feb 2010
        • 2

        #4
        neither of you were helpful at all, i asked a simple question i wanted a simple answer

        Comment

        • newb16
          Contributor
          • Jul 2008
          • 687

          #5
          What am I doing wrong... -
          14: you use somthing that is not declared yet. My compiler generate not a warning but error on this line.
          20 - you use div() function that is not declared.
          ...and how can I fix it?
          14 - remove this line.
          20 - declare function div() before main()

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Did you write the div function yourself, or are you using a library function?

            Comment

            • mush1578
              New Member
              • Feb 2010
              • 15

              #7
              remove or declare div() so it ll be run InsahAllah

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                I thought I had better point out that

                div_t div ( int numerator, int denominator );

                is a standard library function declared in stdlib.h and that the structure div_t is declared in the same header. So the function call is made in the presence of a prototype and div_t is declared.

                Comment

                Working...