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. - #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 - #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;
-
}
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
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();
}
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.
Don't end #define with a semicolon....
Regards
Dheeraj Joshi
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;
thank you whodgson, I ultimately did just eliminate the defines.
@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.
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.
My issues were resolved by and1hotsauce . Thank you
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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)
|
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...
|
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)...
|
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...
|
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...
|
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...
|
by: Jim Langston |
last post by:
In Python 2.5 on intel, the statement
2**2**2**2**2
evaluates to
20035299304068464649790723515602557504478254755697514192650169737108940595563114...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |