any C programmers? - Chicagoland Sportbikes
Chicagoland Sportbikes
 
Open Forum This forum is for all off-topic discussion.

 
LinkBack Thread Tools Display Modes
post #1 of 29 (permalink) Old 09-23-2004, 09:27 PM Thread Starter
pfft.
 
ill_ag's Avatar
 
Join Date: Nov 2003
Location: Houston
Posts: 11,644
Location: Houston
Sportbike: 01 F4i (Well, I HAD one, anyway)
Years Riding: 7
How you found us: I google myself regularly
           
any C programmers?

ok I freaking give up. I really hate programming in C. If I wanted to freaking calculate something, I'd use a calculator. Nevertheless, I need to figure out why these expressions aren't equalling. The ones in bold are the example. The next is supposed to be an equivalent expression to the one above it in bold, but using parentheses.


int a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;

7 + c * -- d / e&nbsp&nbsp&nbsp&nbsp(=4)
7 + ((c * (-- d)) / e)&nbsp&nbsp&nbsp&nbsp(=3) should be 4

a += b += c += 1 + 2&nbsp&nbsp&nbsp(=7)
a += b += (c += (1 + 2))&nbsp&nbsp&nbsp(=23) should be 7


ill_ag is offline  
Sponsored Links
Advertisement
 
post #2 of 29 (permalink) Old 09-23-2004, 09:50 PM
YO MAMA
 
Odysseys's Avatar
 
Join Date: Apr 2002
Location: balls deep in someones mom
Posts: 60,261
Location: balls deep in someones mom
Sportbike: 2010 Electra Glide Police Edition 103cu
Years Riding: a long time!
           
go smoke a joint



Odysseys is offline  
post #3 of 29 (permalink) Old 09-23-2004, 10:26 PM
I break everything!
 
JonGu's Avatar
 
Join Date: Aug 2004
Location: Chicago, IL
Posts: 1,913
Location: Chicago, IL
Sportbike: SV650S, ZX6R, GSXR600
Years Riding: Since 04/2003
How you found us: Google
           
... try changing the ints to floats and see what sorta results you get. And then try systematically removing one part of the equation after another until you get it to match and then add back what you removed to see where it goes wrong.

Jon Gu
CCS AM/NESBA #276
JonGu is offline  
post #4 of 29 (permalink) Old 09-23-2004, 10:39 PM
freaking newbies, man there slow, ha ha ha
 
CRAZe Inc's Avatar
 
Join Date: Sep 2002
Location: San Francisco
Posts: 6,842
Location: San Francisco
Sportbike: Big Wheel
Years Riding: Since 3
How you found us: This is required?
           
I was having trouble figuring out what the problem was until I realized what was happening.


Put:

a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;

between
a += b += c += 1 + 2
&
a += b += (c += (1 + 2));


and see what happens
CRAZe Inc is offline  
post #5 of 29 (permalink) Old 09-23-2004, 10:42 PM
freaking newbies, man there slow, ha ha ha
 
CRAZe Inc's Avatar
 
Join Date: Sep 2002
Location: San Francisco
Posts: 6,842
Location: San Francisco
Sportbike: Big Wheel
Years Riding: Since 3
How you found us: This is required?
           
Same goes for the first one. Your code was fine you just need to reset the values between the expressions.


Well I guess for good programming sake, you wouldn't need to reset all of the values for both since they each only use some, but that's kinda nitpicking.

Last edited by CRAZe Inc; 09-23-2004 at 10:45 PM.
CRAZe Inc is offline  
post #6 of 29 (permalink) Old 09-23-2004, 11:04 PM Thread Starter
pfft.
 
ill_ag's Avatar
 
Join Date: Nov 2003
Location: Houston
Posts: 11,644
Location: Houston
Sportbike: 01 F4i (Well, I HAD one, anyway)
Years Riding: 7
How you found us: I google myself regularly
           
nope it's not that. I have other expressions in the program that work. what my problem is is that I can't figure out how to throw in parentheses so that the new expression is equivalent to the old one. I am having a devil of a time figuring out how, and in what order to assign the + - * += -- and such.
ill_ag is offline  
post #7 of 29 (permalink) Old 09-23-2004, 11:13 PM
freaking newbies, man there slow, ha ha ha
 
CRAZe Inc's Avatar
 
Join Date: Sep 2002
Location: San Francisco
Posts: 6,842
Location: San Francisco
Sportbike: Big Wheel
Years Riding: Since 3
How you found us: This is required?
           
Copy and paste this into your program and tell me the output isn't
4
4

int a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;
int z = (7 + c * -- d / e);
a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;
int x = 7 + ((c * (-- d)) / e);
printf("%d\n%d\n",z,x);


unless I'm not understanding what you're trying to accomplish?

Last edited by CRAZe Inc; 09-23-2004 at 11:15 PM.
CRAZe Inc is offline  
post #8 of 29 (permalink) Old 09-23-2004, 11:14 PM
YO MAMA
 
Odysseys's Avatar
 
Join Date: Apr 2002
Location: balls deep in someones mom
Posts: 60,261
Location: balls deep in someones mom
Sportbike: 2010 Electra Glide Police Edition 103cu
Years Riding: a long time!
           
i am truly retarded!



Odysseys is offline  
post #9 of 29 (permalink) Old 09-24-2004, 12:02 AM
Registered User
 
ing7's Avatar
 
Join Date: May 2004
Location: Oak Brook
Posts: 126
Location: Oak Brook
Sportbike: '04 R6
Years Riding: Months
How you found us: Friend
  
z=7+((c*(-(-d)))/e);
z=((((a+=b)+=c)+=1)+2);

Chris
ing7 is offline  
post #10 of 29 (permalink) Old 09-24-2004, 12:03 AM
Registered User
 
ing7's Avatar
 
Join Date: May 2004
Location: Oak Brook
Posts: 126
Location: Oak Brook
Sportbike: '04 R6
Years Riding: Months
How you found us: Friend
  
priority then work inside out

Chris
ing7 is offline  
post #11 of 29 (permalink) Old 09-24-2004, 12:11 AM
 
Join Date: Aug 2004
Posts: 75
 
the snausberries taste like snausberries
r1wheel68 is offline  
post #12 of 29 (permalink) Old 09-24-2004, 09:06 AM Thread Starter
pfft.
 
ill_ag's Avatar
 
Join Date: Nov 2003
Location: Houston
Posts: 11,644
Location: Houston
Sportbike: 01 F4i (Well, I HAD one, anyway)
Years Riding: 7
How you found us: I google myself regularly
           
yeah, craze-- it SHOULD work, but it doesn't.
the point of the exercise is to change nothing but adding parentheses.

it sucks.
ill_ag is offline  
post #13 of 29 (permalink) Old 09-24-2004, 09:49 AM
Registered User
 
BusaDave's Avatar
 
Join Date: Apr 2002
Location: Naperville
Posts: 5,002
Location: Naperville
Sportbike: 2002 Turbo Hayabusa
Years Riding: Lost Track
How you found us: Tony
           
Nice little excersize in order of precidence, but absolutely horrible real-world programming. Any statement that requires that much work to understand is very poorly constructed (obfuscated). Nice little thought puzzle, but don't let your boss catch you programming that way!

Dave
BusaDave is offline  
post #14 of 29 (permalink) Old 09-24-2004, 10:56 AM
__________
 
Dirtbiker's Avatar
 
Join Date: Mar 2004
Location: Somewhere else.
Posts: 6,365
Location: Somewhere else.
Sportbike: Resurrection Built YZ250F, Various European Junk
Years Riding: Yes
How you found us: SBN
           
WTF?

That's some language you guys got there. And you talk like that all the time huh?




Dirtbiker is offline  
post #15 of 29 (permalink) Old 09-24-2004, 11:16 AM
Rev
 
Join Date: May 2004
Posts: 2,438
 
Quote:
int a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;

7 + c * -- d / e (=4)
7 + ((c * (-- d)) / e) (=3) should be 4

a += b += c += 1 + 2 (=7)
a += b += (c += (1 + 2)) (=23) should be 7
Are you using this?
http://www.difranco.net/cop2220/op-prec.htm

Let's analyze...

7 + 5 * --(-7) / 11 = 7 + -40 / 11 = -3

How in hell do you come up with 4?

-- is unary pre-decrement, so subtract 1 to -7 prior to multiplying and dividing by 11 .. Am I wrong?

Next:
7 + ((c * (-- d)) / e) (=3) should be 4

7 + ((5 * (-- -7)) / 11)
= 7 + ((5 * (-8)) / 11)
= 7 + (-40)/ 11)

Whaa??

Nope ... I'm not doing the next ones ... my head hurts g
Rev is offline  
post #16 of 29 (permalink) Old 09-24-2004, 11:33 AM
CLSB's Florida Chapter.
 
MoparBoyy's Avatar
 
Join Date: Apr 2004
Location: Apopka, Florida
Posts: 22,652
Location: Apopka, Florida
Sportbike: Ducati
Years Riding: 3 days
How you found us: unemployment office
           
Send a message via AIM to MoparBoyy
Quote:
Originally posted by Odysseys
i am truly retarded!
so Ken.. how bout them Cubs...

I have no idea what these peeps are talking about.

-Mopar

1997 Dodge Viper GTS
2013 Dodge Dart Rallye
MoparBoyy is offline  
post #17 of 29 (permalink) Old 09-24-2004, 12:38 PM
Registered User
 
BusaDave's Avatar
 
Join Date: Apr 2002
Location: Naperville
Posts: 5,002
Location: Naperville
Sportbike: 2002 Turbo Hayabusa
Years Riding: Lost Track
How you found us: Tony
           
Quote:
int a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;

7 + c * -- d / e (=4)
7 + ((c * (-- d)) / e) (=3) should be 4

a += b += c += 1 + 2 (=7)
a += b += (c += (1 + 2)) (=23) should be 7
Let's try this:

7 + c * (--d) / e
7 + 5 * (--(-7)) / 11
7 + 5 * -8 / 11
7 + (-40) / 11
7 + ( -3 )
4

a += b += c += 1 + 2
a += b += c += 3
a += b += 8 ( c = 8 )
a += 5 ( b = 5 )
7 ( a = 7 )

+= has lowest precedence and reverses the order from normal l-to-r addition.

Dave
BusaDave is offline  
post #18 of 29 (permalink) Old 09-24-2004, 01:45 PM
Rev
 
Join Date: May 2004
Posts: 2,438
 
Quote:
Originally posted by BusaDave
Let's try this:

7 + c * (--d) / e
7 + 5 * (--(-7)) / 11
7 + 5 * -8 / 11
7 + (-40) / 11
7 + ( -3 )
4

+= has lowest precedence and reverses the order from normal l-to-r addition.
OK I see

-40/11 is actually an int(40/11)

void main(void)
{
int i=0;
for(i;i<1000;i++)
printf("I'm retarded\r\n");
}

Rev is offline  
post #19 of 29 (permalink) Old 09-24-2004, 01:50 PM
yo quiero su taco
 
whiteSeatEnvy's Avatar
 
Join Date: Dec 2002
Location: Woodridge
Posts: 12,745
Location: Woodridge
Sportbike: Honda CBR 954 blk/slvr
Years Riding: 10 years
How you found us: They found me. Follow the white rabbit.
           
Quote:
Originally posted by Rev
OK I see

-40/11 is actually an int(40/11)

void main(void)
{
int i=0;
for(i;i<1000;i++)
printf("I'm retarded\r\n");
}

More like:

void main(void)
{
int i=0;
for(i;i>-1;i++)
printf("I'm retarded\r\n");
}



"includes 10 used-car dealers or auto repair shops, 11 liquor stores and bars--two of which advertise lingerie fashion shows and a third billed as a "gentlemen's club"--three cut-rate motels and one trailer park. The squat, brick municipal building is next to a currency exchange and a few steps from an adult video store. The bars open at 10 a.m. and close at 6:30 a.m."

Quote:
Originally Posted by admin View Post
Something must be fishy...I am going to go poke around in the back end..
whiteSeatEnvy is offline  
post #20 of 29 (permalink) Old 09-24-2004, 01:55 PM
Rev
 
Join Date: May 2004
Posts: 2,438
 
Quote:
Originally posted by whiteSeatEnvy
More like:

void main(void)
{
int i=0;
for(i;i>-1;i++)
printf("I'm retarded\r\n");
}


while(1)
{
sprintf(""\r\n);
}
Rev is offline  
post #21 of 29 (permalink) Old 09-24-2004, 02:06 PM
Registered User
 
DieselBoy's Avatar
 
Join Date: Aug 2004
Location: Naperville IL
Posts: 701
Location: Naperville IL
Sportbike: 08 R6 , CRF250R
Years Riding: 1
How you found us: chicagorussionriders
           
Re: any C programmers?

Quote:
Originally posted by ill_ag
ok I freaking give up. I really hate programming in C. If I wanted to freaking calculate something, I'd use a calculator. Nevertheless, I need to figure out why these expressions aren't equalling. The ones in bold are the example. The next is supposed to be an equivalent expression to the one above it in bold, but using parentheses.


int a = 2, b = -3, c = 5, d = -7, e = 11, f = -3;

7 + c * -- d / e&nbsp&nbsp&nbsp&nbsp(=4)
7 + ((c * (-- d)) / e)&nbsp&nbsp&nbsp&nbsp(=3) should be 4

a += b += c += 1 + 2&nbsp&nbsp&nbsp(=7)
a += b += (c += (1 + 2))&nbsp&nbsp&nbsp(=23) should be 7


if you put these statements in one code block
--d will decrease in the first statement hence
--d in the second statement evaluates to -9

DieselBoy is offline  
post #22 of 29 (permalink) Old 09-24-2004, 07:09 PM
demonbane
Guest
 
Posts: n/a
I'm wondering if this is a trick question or not. If it's not meant to be a trick question, then someone just didn't tell you that you're allowed to reset the variables between runs. (Either that or you don't have to RUN the examples, only refer to them.) If that's not the case, however, Ing has put up the solution. By breaking the decrement operator into two negation operators (by using parenthesis) you get to maintain your negative value without decrementing it which allows you to get the correct answer.
post #23 of 29 (permalink) Old 09-24-2004, 08:20 PM
yo quiero su taco
 
whiteSeatEnvy's Avatar
 
Join Date: Dec 2002
Location: Woodridge
Posts: 12,745
Location: Woodridge
Sportbike: Honda CBR 954 blk/slvr
Years Riding: 10 years
How you found us: They found me. Follow the white rabbit.
           
Quote:
Originally posted by demonbane
I'm wondering if this is a trick question or not. If it's not meant to be a trick question, then someone just didn't tell you that you're allowed to reset the variables between runs. (Either that or you don't have to RUN the examples, only refer to them.) If that's not the case, however, Ing has put up the solution. By breaking the decrement operator into two negation operators (by using parenthesis) you get to maintain your negative value without decrementing it which allows you to get the correct answer.
Busadave gave the answer up above.

"includes 10 used-car dealers or auto repair shops, 11 liquor stores and bars--two of which advertise lingerie fashion shows and a third billed as a "gentlemen's club"--three cut-rate motels and one trailer park. The squat, brick municipal building is next to a currency exchange and a few steps from an adult video store. The bars open at 10 a.m. and close at 6:30 a.m."

Quote:
Originally Posted by admin View Post
Something must be fishy...I am going to go poke around in the back end..
whiteSeatEnvy is offline  
post #24 of 29 (permalink) Old 09-24-2004, 08:43 PM
Registered User
 
BusaDave's Avatar
 
Join Date: Apr 2002
Location: Naperville
Posts: 5,002
Location: Naperville
Sportbike: 2002 Turbo Hayabusa
Years Riding: Lost Track
How you found us: Tony
           
Quote:
Originally posted by demonbane
I'm wondering if this is a trick question or not. If it's not meant to be a trick question, then someone just didn't tell you that you're allowed to reset the variables between runs. (Either that or you don't have to RUN the examples, only refer to them.) If that's not the case, however, Ing has put up the solution. By breaking the decrement operator into two negation operators (by using parenthesis) you get to maintain your negative value without decrementing it which allows you to get the correct answer.
The parens are only to help you understand, You can't legally break up the -- operator. This violates the rules of the C language. Now if it were - - it would be an entirely different expression, but you don't get to pick & choose.

Dave
BusaDave is offline  
post #25 of 29 (permalink) Old 09-25-2004, 09:17 AM
demonbane
Guest
 
Posts: n/a
Yes, putting a parenthesis between -- destroys the decrement operator, but if this was a school project meant as a brain-teaser and the directions were that you could ONLY use parenthesis, then it would be a rather fun exercise.
post #26 of 29 (permalink) Old 09-26-2004, 11:43 AM Thread Starter
pfft.
 
ill_ag's Avatar
 
Join Date: Nov 2003
Location: Houston
Posts: 11,644
Location: Houston
Sportbike: 01 F4i (Well, I HAD one, anyway)
Years Riding: 7
How you found us: I google myself regularly
           
Re: Re: any C programmers?

Quote:
Originally posted by DieselBoy
if you put these statements in one code block
--d will decrease in the first statement hence
--d in the second statement evaluates to -9

and that, my friend, was the answer. I went to my TA later the next day and was hit over the head with "you have to reset the values anytime you use the decrement/increment operators" Oops.

But each one of your solutions worked (except the one where the inc/dec operators were broken up)

Thanks for all your help guys. Maybe I'll get out of school sooner (and back to Chicago sooner) because of it.
ill_ag is offline  
post #27 of 29 (permalink) Old 09-26-2004, 04:36 PM
Registered User
 
BusaDave's Avatar
 
Join Date: Apr 2002
Location: Naperville
Posts: 5,002
Location: Naperville
Sportbike: 2002 Turbo Hayabusa
Years Riding: Lost Track
How you found us: Tony
           
Did the problem say that the statements were inthe same code block? That definately would make a difference!

Dave
BusaDave is offline  
post #28 of 29 (permalink) Old 09-27-2004, 12:35 AM
demonbane
Guest
 
Posts: n/a
ill_ag, since the answer was to just re-init the variables each time I'm guessing this is a 100-level CS course or so?

Personally, I much prefer the method of splitting the decrement operator with the parens. That's the type of trick question that would be really fun to use for bonus points... (Makes me wish I was still in school so I could work it into a quiz with one of the prof's I TA'd for... )
post #29 of 29 (permalink) Old 09-27-2004, 01:03 AM
yo quiero su taco
 
whiteSeatEnvy's Avatar
 
Join Date: Dec 2002
Location: Woodridge
Posts: 12,745
Location: Woodridge
Sportbike: Honda CBR 954 blk/slvr
Years Riding: 10 years
How you found us: They found me. Follow the white rabbit.
           
Quote:
Originally posted by demonbane
ill_ag, since the answer was to just re-init the variables each time I'm guessing this is a 100-level CS course or so?

Personally, I much prefer the method of splitting the decrement operator with the parens. That's the type of trick question that would be really fun to use for bonus points... (Makes me wish I was still in school so I could work it into a quiz with one of the prof's I TA'd for... )
Wow, what a dork. Just messin with ya. No worries, I have a BS in Computer Science. Now, I know where all those "trick" questions came from -- bored TAs. Those postfix vs. prefix operator trick questions came up more than once in my classes.

"includes 10 used-car dealers or auto repair shops, 11 liquor stores and bars--two of which advertise lingerie fashion shows and a third billed as a "gentlemen's club"--three cut-rate motels and one trailer park. The squat, brick municipal building is next to a currency exchange and a few steps from an adult video store. The bars open at 10 a.m. and close at 6:30 a.m."

Quote:
Originally Posted by admin View Post
Something must be fishy...I am going to go poke around in the back end..
whiteSeatEnvy is offline  
Reply

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the Chicagoland Sportbikes forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome