Trying to do Simple Multiplication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kfindley
    New Member
    • Feb 2010
    • 6

    Trying to do Simple Multiplication

    I've been looking online but am having trouble finding sources on using C for basic multiplication. I'm assuming this is not the original purpose of C, but its what I need to do.

    If anyone can see glaring errors i'm making please let me know!

    I've tried declaring my variables as both doubles and int 's but to no avail.

    Code:
    #include <stdio.h>
     #include <math.h>
     int main()
     {
         /* the given dimensions of the tank in meters*/
         #define DIAMETER 5.0;
         #define HEIGHT 10.0;
         /* conversion factors*/
         #define M2F 3.2808
         #define F2G 7.481
         
         /* Declare my variables*/
         int DIAMETER_FEET,HEIGHT_FEET,VOLUME_FEET,VOLUME;
         
         /* define my variables*/
         &DIAMETER_FEET = DIAMETER * M2F;
         &HEIGHT_FEET = HEIGHT * M2F;
         &VOLUME_FEET = DIAMETER_FEET * HEIGHT_FEET;
         &VOLUME = VOLUME_FEET * F2G;
         
         /* output statement*/
         printf(VOLUME);
         
         return 0;
    }

    I updated my code but its still not working. The specific error i am getting is:
    : In function 'main':
    :36: error: expected ')' before ';' token
    :37: error: expected ')' before ';' token
    :39: error: expected ')' before ';' token

    Code:
    #include <stdio.h>
     #include <math.h>
     int main()
     {
         /* Declare my variables*/
         double DIAMETER_FEET,HEIGHT_FEET,VOLUME_FEET,VOLUME;
         
         /* the given dimensions of the tank in meters*/
         #define DIAMETER 5.0;
         #define HEIGHT 10.0;
         /* conversion factors*/
         #define M2F 3.2808;
         #define F2G 7.481;
         
         /* define my variables*/
         DIAMETER_FEET = (DIAMETER * M2F);
         HEIGHT_FEET = (HEIGHT * M2F);
         VOLUME_FEET = (DIAMETER_FEET * HEIGHT_FEET);
         VOLUME = (VOLUME_FEET * F2G);
         
         /* output statement*/
         printf("%f", VOLUME);
         
         return 0;
    }
    Last edited by Banfa; Feb 22 '10, 10:26 PM. Reason: Added [code] ... [/code] tags
  • and1hotsauce
    New Member
    • Feb 2010
    • 1

    #2
    hi. When your defining your values, do it before int main()

    also the correct syntax is define M2F 3.208

    there is no semi-colon

    #include <stdio.h>
    #include <math.h>

    /* the given dimensions of the tank in meters*/
    #define DIAMETER 5.0
    #define HEIGHT 10.0
    /* conversion factors*/
    #define M2F 3.2808
    #define F2G 7.481
    int main()
    {
    /* Declare my variables*/
    double DIAMETER_FEET,H EIGHT_FEET,VOLU ME_FEET,VOLUME;


    /* define my variables*/
    DIAMETER_FEET = (DIAMETER * M2F);
    HEIGHT_FEET = (HEIGHT * M2F);
    VOLUME_FEET = (DIAMETER_FEET * HEIGHT_FEET);
    VOLUME = (VOLUME_FEET * F2G);

    /* output statement*/
    printf("%f", VOLUME);

    getch();
    }

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      They are not values, they are variables and if they are declared outside of the main() function they will have global scope which is not recommended The experts invariably coach that a variable should only be given enough scope to serve its purpose......an d no more.

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        Don't end #define with a semicolon....

        Regards
        Dheeraj Joshi

        Comment

        • mush1578
          New Member
          • Feb 2010
          • 15

          #5
          int a,b,c;
          cout<<"enter the value of a"<<endl;
          cin>>a;

          cout<<"enter the value of b"<<endl;
          cin>>b;
          c=a*b;
          cout<<"the multiplication is =="<<c<<endl;

          Comment

          • kfindley
            New Member
            • Feb 2010
            • 6

            #6
            thank you whodgson, I ultimately did just eliminate the defines.

            Comment

            • kfindley
              New Member
              • Feb 2010
              • 6

              #7
              Originally posted by mush1578
              int a,b,c;
              cout<<"enter the value of a"<<endl;
              cin>>a;

              cout<<"enter the value of b"<<endl;
              cin>>b;
              c=a*b;
              cout<<"the multiplication is =="<<c<<endl;
              I'm not sure what this is at all but thank you for the reply.
              I think i must just be unfamiliar with the syntax you are using.

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                kfindley, it is not clear if your problem has been solved.

                If not I suggest you post your current code (using [code] ... [/code] tags round it) and your current set of errors/problems.

                Comment

                • kfindley
                  New Member
                  • Feb 2010
                  • 6

                  #9
                  My issues were resolved by and1hotsauce . Thank you

                  Comment

                  Working...