473,465 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trying to do Simple Multiplication

6 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  #include <math.h>
  3.  int main()
  4.  {
  5.      /* the given dimensions of the tank in meters*/
  6.      #define DIAMETER 5.0;
  7.      #define HEIGHT 10.0;
  8.      /* conversion factors*/
  9.      #define M2F 3.2808
  10.      #define F2G 7.481
  11.  
  12.      /* Declare my variables*/
  13.      int DIAMETER_FEET,HEIGHT_FEET,VOLUME_FEET,VOLUME;
  14.  
  15.      /* define my variables*/
  16.      &DIAMETER_FEET = DIAMETER * M2F;
  17.      &HEIGHT_FEET = HEIGHT * M2F;
  18.      &VOLUME_FEET = DIAMETER_FEET * HEIGHT_FEET;
  19.      &VOLUME = VOLUME_FEET * F2G;
  20.  
  21.      /* output statement*/
  22.      printf(VOLUME);
  23.  
  24.      return 0;
  25. }

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

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  #include <math.h>
  3.  int main()
  4.  {
  5.      /* Declare my variables*/
  6.      double DIAMETER_FEET,HEIGHT_FEET,VOLUME_FEET,VOLUME;
  7.  
  8.      /* the given dimensions of the tank in meters*/
  9.      #define DIAMETER 5.0;
  10.      #define HEIGHT 10.0;
  11.      /* conversion factors*/
  12.      #define M2F 3.2808;
  13.      #define F2G 7.481;
  14.  
  15.      /* define my variables*/
  16.      DIAMETER_FEET = (DIAMETER * M2F);
  17.      HEIGHT_FEET = (HEIGHT * M2F);
  18.      VOLUME_FEET = (DIAMETER_FEET * HEIGHT_FEET);
  19.      VOLUME = (VOLUME_FEET * F2G);
  20.  
  21.      /* output statement*/
  22.      printf("%f", VOLUME);
  23.  
  24.      return 0;
  25. }
Feb 13 '10 #1

✓ answered by and1hotsauce

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,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("%f", VOLUME);

getch();
}

8 4963
and1hotsauce
1 New Member
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,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("%f", VOLUME);

getch();
}
Feb 14 '10 #2
whodgson
542 Contributor
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......and no more.
Feb 15 '10 #3
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Don't end #define with a semicolon....

Regards
Dheeraj Joshi
Feb 15 '10 #4
mush1578
15 New Member
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;
Feb 16 '10 #5
kfindley
6 New Member
thank you whodgson, I ultimately did just eliminate the defines.
Feb 22 '10 #6
kfindley
6 New Member
@mush1578
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.
Feb 22 '10 #7
Banfa
9,065 Recognized Expert Moderator Expert
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.
Feb 22 '10 #8
kfindley
6 New Member
My issues were resolved by and1hotsauce . Thank you
Feb 23 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark Dickinson | last post by:
Can anyone either reproduce or explain the following apparently inconsistent behaviours of __add__ and __mul__? The class Gaussian provides a sub-bare-bones implementation of Gaussian integers (a...
9
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
87
by: Vijay Kumar R Zanvar | last post by:
Hi, Why multiplication of pointers is not allowed? Till now I only know this, but not the reason why! PS: As a rule, I searched the FAQ, but could not find an answer. -- Vijay Kumar R...
5
by: Paul McGuire | last post by:
Does Python's run-time do any optimization of multiplication operations, like it does for boolean short-cutting? That is, for a product a*b, is there any shortcutting of (potentially expensive)...
3
by: beachlounger | last post by:
Using C++ language to complete this homework 1. Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The...
0
by: lituncse | last post by:
dear friends, i have come across a problem which is difficult to solve for me.it's about starssen's matrix multiplication.in general matrix multiplication we need 8 multiplications and 4 additions...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
31
by: Jim Langston | last post by:
In Python 2.5 on intel, the statement 2**2**2**2**2 evaluates to 20035299304068464649790723515602557504478254755697514192650169737108940595563114...
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
5
by: just curious | last post by:
Create a C++ console application that uses a while loop to count, total, and average a series of positive integers entered by a user. The user enters a –1 to signal the end of data input and to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.