473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I am having trouble getting my code to compile.

I cannot seem to get my program to compile correctly.
The error codes I am receiving are:
"ISO C90 forbids mixed declarations and code"(lines 31,33,35
and also:
"Invalid operands to binary %"(lines 33,35)

the following lines are
30. [*gallons=usercups/GAL;]
31. [float remgal=usercups%GAL;]
32. [*quarts=remgal/QRT;]
33. [float remquart=quarts%QRT;]
34. [*pints=remquart/PNT;]
35. [float rempint=pints%PNT;]
36. [*cups=rempint;]

GAL, QRT, and PNT are defined before any function is started.

Please help me understand what I am doing wrong.
Jul 10 '10 #1
4 1416
Update:
I figured out the mixed declarations and code thing. I listed all declarations at the beginning and have the calculations belowand eliminated that error. However, I am still receiving the "Invalid operands to binary %" error. I do not really understand this error.
Thank you
Jul 10 '10 #2
The % operator is only defined for integers. That is something like
int a=10;
int b=7;
int c=a%b;

is O.K. but that would fail if a and b were doubles or floats.
So pints, quarts, PNT and QRT should be declared as ints, or else you should cast them as such.
Also check out http://bytes.com/topic/c/answers/495...uble-variables
-Tom
Jul 10 '10 #3
I am still having problems. I am still getting the error code "Invalid operands to binary %"

I thought that I had everything declared correctly.

The following is the section of code that is giving me problems:

24.void liquid(int cups1, int *gal1, int *quart2, int *pints3, int *cups4)
25.
26. {
27. int remgal=cups1%GAL;
28. int remquart=quart2%QRT;
29. int rempint=pints3%PNT;
30.
31. *gal1=cups1/GAL;
32. *quart2=remgal/QRT;
33. *pints3=remquart/PNT;
34. *cups4=rempint;
35. }

My compiler is giving that error for lines 28 and 29 but not for line 27 so I am confused.
GAL is defined as 16
QRT is defined as 4
PNT is defined as 2

Wouldn't defining them be just as good as declaring them as ints?
Jul 10 '10 #4
weaknessforcats
9,208 Expert Mod 8TB
28. int remquart=quart2%QRT;
29. int rempint=pints3%PNT;

quart2 and pints3 are int*. The % operator does not work with pointers. It works for integer types only.
Jul 11 '10 #5

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

Similar topics

0
by: Mason Hoke | last post by:
I am using SQLXML3 to return me XML formatted result. All the attributes are double quoted. When I try to response.write it as an XML data island to the client side like nothing comes over to the...
1
by: tperri | last post by:
Hi everyone, I have an .aspx file that is used by an external program to perform a function. There is no code behind, all code and HTML is contained in one file. the structure is like this: ...
3
by: BTInternet | last post by:
-- OHM ( Terry Burns ) . . . One-Handed-Man . . . If U Need My Email ,Ask Me Time flies when you don't know what you're doing
2
by: mikepolitowski | last post by:
Hi folks, I am have been trying to solve this problem for quite some time now and would appreciate any advice. I have been trying to call a code-behind function that is defined in my aspx.cs...
2
by: Jake Barnes | last post by:
I've read over the documentation for these effects: http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo I want to include them on my page. I tried attaching using onload, but...
2
by: gnrdtud | last post by:
I'm trying to teach myself how to use CSS to create site layouts. I've got a mock up of a really basic site, and through a lot of trial and error i've managed to get a working layout... in FF. IE6,...
13
by: angwe23 | last post by:
I've got to fix a system that was basically handed to me. As it currently functions we have four tables as such: 1) Project Hours (includes EmployeeID, ProjectID, Date, Hours) 2) Payrates...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.