Post new topic Reply to topic  [ 21 posts ] 

Board index : Music Talk : Rock/Pop

Author Message
 Post subject: does anyone here know c++?? cause i need some help.
PostPosted: Mon Oct 17, 2005 4:04 pm 
Offline
Troubador
User avatar

Joined: Mon Oct 25, 2004 12:23 pm
Posts: 3742
im learning c++ and one the assignments we've been given is to write a program to determine absolute values. theres something wrong with it and i cant figure out what. i know there are a couple techies on the board so hopefully one of you can help me.

#include <iostream.h>

void main()
{

double value, answer;

cout <<"Please enter a value: ";
cin >> value;

if (value = 0);
cout <<"Your number is zero.";

if (value < 0);
cout <<"Your number is positive.";

if (value > 0);
answer = value * -1;
cout <<"The absolute value of " <<value <<" is " <<answer <" . ";
}


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:05 pm 
Offline
Go Platinum
User avatar

Joined: Mon Oct 25, 2004 10:55 am
Posts: 8110
Location: chicago
this is resurfacing terrible nightmares from college

_________________
[quote="paper"]listen to robotboy.[/quote]


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:09 pm 
Offline
Self-Released 7-Inch
User avatar

Joined: Mon Oct 25, 2004 5:06 pm
Posts: 1100
Location: STL
at least it's not FORTRAN. fuck that shit.


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:15 pm 
Offline
Go Platinum
User avatar

Joined: Sat Dec 04, 2004 1:48 am
Posts: 7332
Location: Cloud 3.14159
Looks like you have your tests backwards (greater than and less than).

_________________
I remain,
:-Peter, aka :-Dusty :-(halk


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:18 pm 
Offline
Go Platinum
User avatar

Joined: Mon Oct 25, 2004 8:37 pm
Posts: 7618
Location: Knee-deep and sinking
You need double == in your if tests.

A single = is to set a value, a double == is for compares.


Last edited by mutty on Mon Oct 17, 2005 4:18 pm, edited 1 time in total.

Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:18 pm 
Offline
Go Platinum
User avatar

Joined: Wed Jan 26, 2005 12:58 pm
Posts: 7205
Location: Kzoo, Michigan
yeah your logic is backwards...

also use else ifs (if.....else if.....else...) - moer efficent

instead of 3 separate ifs...

ditto on the == as well


Back to top
 Profile ICQ 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:23 pm 
Offline
Go Platinum
User avatar

Joined: Sat Dec 04, 2004 1:48 am
Posts: 7332
Location: Cloud 3.14159
Also, I don't think you want all those semicolons there (at the end of each if).

_________________
I remain,
:-Peter, aka :-Dusty :-(halk


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:24 pm 
Offline
Troubador
User avatar

Joined: Mon Oct 25, 2004 12:23 pm
Posts: 3742
thanks for the help so far. and thanks for spotting my equals and greater/less than errors. it still wont compile correctly, though. this is the error message it spits out. (i didnt paste the whole thing, just the important part)

Code:
17 > if (value == 0);

ERROR >> error in statement

Finished.
1 error reported.


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:25 pm 
Offline
Go Platinum
User avatar

Joined: Sat Dec 04, 2004 1:48 am
Posts: 7332
Location: Cloud 3.14159
Northern Soul Wrote:
thanks for the help so far. and thanks for spotting my equals and greater/less than errors. it still wont compile correctly, though. this is the error message it spits out. (i didnt paste the whole thing, just the important part)

Code:
17 > if (value == 0);

ERROR >> error in statement

Finished.
1 error reported.
It's the semicolon -- take it off the other(s), as well.

_________________
I remain,
:-Peter, aka :-Dusty :-(halk


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:27 pm 
Offline
Troubador
User avatar

Joined: Mon Oct 25, 2004 12:23 pm
Posts: 3742
oh crap, yeah it was the semi colons that were screwing it up. all right, heres problem number 2.

Code:
125 > cout <<"The absolute value of " <<value <<" is " <<answer <" . ";

ERROR >> type cannot be string or array
26 > }

Finished.
1 error reported.


which leads me to believe im going to have to rewrite it as an if else type thing.

edit: copied and pasted the wrong error.


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:34 pm 
Offline
Go Platinum
User avatar

Joined: Wed Jan 26, 2005 12:58 pm
Posts: 7205
Location: Kzoo, Michigan
cout <<"The absolute value of " <<value <<" is " <<answer <" . ";

need another less than


Back to top
 Profile ICQ 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:36 pm 
Offline
Troubador
User avatar

Joined: Mon Oct 25, 2004 12:23 pm
Posts: 3742
awesome, it works now. thanks everyone!!!


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:40 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 6:11 pm
Posts: 8881
Location: *3
yeah, watch those semi-colons. only supposed to be used at end-of-statement!

_________________
@--


Back to top
 Profile WWW 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 7:48 pm 
Offline
Failed Reunion

Joined: Tue Nov 23, 2004 12:53 am
Posts: 4263
Location: any suggestions?
[PopTodd]I don't know what the christ any of the above means, but the fact that you all pitched in to help out is one more example of why Obner is A-OK.[/PopTodd]

_________________
Kwame Kilpatrick texted to his mistress: "NEXT TIME, JUST TELL ME TO SIT DOWN, SHUT UP, and DO YOUR THING! I'm fucked up now!"


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:06 pm 
Offline
Post-Breakup Solo Project
User avatar

Joined: Fri Oct 29, 2004 12:48 am
Posts: 3259
Location: Philadelphia/New Jersey
aerodynamics Wrote:
at least it's not FORTRAN. fuck that shit.


I'm taking FORTRAN this semester...ugh

_________________
catswilleatyou Wrote:
my diet is 75% buffalo chicken so i don't trust myself to go commando


http://www.strikerbill.com Check it out hombre.


Back to top
 Profile WWW 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:08 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 6:11 pm
Posts: 8881
Location: *3
Vanlandingham Wrote:
aerodynamics Wrote:
at least it's not FORTRAN. fuck that shit.


I'm taking FORTRAN this semester...ugh


fortran's the worst i've seen since assembler language. c++ is close.

i much prefer java's oo approach.

_________________
@--


Back to top
 Profile WWW 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:12 pm 
Offline
Post-Breakup Solo Project
User avatar

Joined: Fri Oct 29, 2004 12:48 am
Posts: 3259
Location: Philadelphia/New Jersey
Well Fortran is a requirement for my major, but they are getting rid of it next semester. Will have to learn Java instead.

_________________
catswilleatyou Wrote:
my diet is 75% buffalo chicken so i don't trust myself to go commando


http://www.strikerbill.com Check it out hombre.


Back to top
 Profile WWW 
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:25 pm 
Offline
Troubador
User avatar

Joined: Mon Oct 25, 2004 12:23 pm
Posts: 3742
why would they make you learn fortran? at least c++ is somewhat useful. after youre done learning it you can pretty much throw out everything you learned. what a totally useless and ancient language. just about anything would be better than that. i have a programming friend who learned fortran first, and now never uses it. (because of course, its totally useless)


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:48 pm 
Offline
Go Platinum
User avatar

Joined: Sat Dec 04, 2004 1:48 am
Posts: 7332
Location: Cloud 3.14159
Fortran is still used quite a bit. Nothing beats it for number-crunching and reuse.

_________________
I remain,
:-Peter, aka :-Dusty :-(halk


Back to top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:27 pm 
Offline
Post-Breakup Solo Project
User avatar

Joined: Fri Oct 29, 2004 12:48 am
Posts: 3259
Location: Philadelphia/New Jersey
My professor is a full believer in fortran. He's all disheartened that he won't be allowed to teach it anymore after this semester. But I figure if I know that, learn java, and bone up on my c++ (took it years ago), then I'll be ok in the long run.

_________________
catswilleatyou Wrote:
my diet is 75% buffalo chicken so i don't trust myself to go commando


http://www.strikerbill.com Check it out hombre.


Back to top
 Profile WWW 
 
 Post subject: Re: does anyone here know c++?? cause i need some help.
PostPosted: Mon Oct 17, 2005 11:34 pm 
Offline
Winona Ryder wears my t-shirt on TV

Joined: Mon Oct 25, 2004 3:10 pm
Posts: 2532
Location: Cleveland, OH
Java, C++ and especially Visual Basic .NET are the best. Everything else is un-American.


Back to top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ] 

Board index : Music Talk : Rock/Pop


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Style by Midnight Phoenix & N.Design Studio
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.