View previous topic :: View next topic |
Author |
Message |
South-American Fire Ant Registered User
Joined: 25 Feb 2002
Posts: 26
|
Posted: Mon May 06, 2002 2:28 pm Post subject: C++ PROGRAMMIN' r u any good? |
|
|
#include <iostream.h>
int main()
{
int SomeVariable = 5;
cout << "SomeVariable: " << SomeVariable << "\n";
int *pVar = & SomeVariable;
int pVar = 9;
cout << "SomeVariable: " << *pVar << "\n";
return 0;
}
does anyone know whats wrong with this code?
i'm in HS and i suck at C++.
j0r phiaer anth,
m3 |
|
Back to top |
|
|
Kjeldorian Royal Guard 42 Registered User
Joined: 30 Nov 2001 Location: Dripping Springs, TX Posts: 5563
|
Posted: Mon May 06, 2002 2:37 pm Post subject: |
|
|
You left out 4.
Or was it 8?
hmmmm....Oh yeah, I have no idea what you are talking about! |
|
Back to top |
|
|
YourPowersAreWeakOldMan Registered User
Joined: 20 Aug 2001 Location: Houston Texas USA Posts: 1745
|
Posted: Mon May 06, 2002 2:40 pm Post subject: |
|
|
Hey man, I only do other people's homework for cash $$. _________________ World of Warcraft:
Bleeding Hollow PVP Server as Mortibund (undead mage) |
|
Back to top |
|
|
three_gunn Registered User
Joined: 04 May 2002 Location: Hawthorne, CA Posts: 424
|
Posted: Mon May 06, 2002 2:46 pm Post subject: |
|
|
YourPowersAreWeakOldMan wrote: | Hey man, I only do other people's homework for cash $$. |
yeah!...now give me your lunch money, South-American Fire Ant!!
j/k man...im just jealous that you know C++ and youre still in highschool...back in my day...my school only had 'Power PC' macintosh used for typing classes |
|
Back to top |
|
|
Snaggletooth Guest
|
Posted: Mon May 06, 2002 2:49 pm Post subject: Re: C++ PROGRAMMIN' r u any good? |
|
|
South-American Fire Ant wrote: |
int pVar = 9;
cout << "SomeVariable: " << *pVar << "\n"; |
It's been a while since I did any C++, but I think you want this
to look like this
or maybe like this
Don't blame me if it compiles wrong again.... I'm rusty....and I don't do other people's homework unless they're a girl, and hot. Or they're gonna pay me lots of $$$$
Last edited by Snaggletooth on Mon May 06, 2002 3:21 pm; edited 1 time in total |
|
Back to top |
|
|
5th GHG E.G. Mine Registered User
Joined: 02 Jan 2002 Location: Transcending 1337. Posts: 1426
|
Posted: Mon May 06, 2002 3:10 pm Post subject: |
|
|
I'd help you if I could but C++ is next year for me. _________________ http://www.chronixradio.com |
|
Back to top |
|
|
FingerDemon Registered User
Joined: 24 Aug 2001 Location: Virginia Posts: 551
|
Posted: Mon May 06, 2002 3:14 pm Post subject: |
|
|
Fire Ant,
Also, I think you are declaring that variable twice. I don't program in C++, so maybe that's something you can do with pointers or something. But generally you declare the variable once like
int whatever = 0;
But then to assign it a value, you just go
whatever = 20,000,000;
You don't need to repeat the "int" every time.
Good luck, it might suck to be working on this now, but someday you'll hate something else WAAY more than this. Hmmm.... Ok, that probably didn't make you feel any better, so I'll stop now.
<TVB>FingerDemon-VS
P.S. And three gunn, I still remember my Dad going out to buy one of the first handheld calculators sold commercially. The thing was about the size of a brick, no kidding. And teachers in my school were of the firm opinion that no machine would ever replace the mimeograph, that modern marvel. |
|
Back to top |
|
|
three_gunn Registered User
Joined: 04 May 2002 Location: Hawthorne, CA Posts: 424
|
Posted: Mon May 06, 2002 3:28 pm Post subject: |
|
|
FingerDemon wrote: | P.S. And three gunn, I still remember my Dad going out to buy one of the first handheld calculators sold commercially. The thing was about the size of a brick, no kidding. And teachers in my school were of the firm opinion that no machine would ever replace the mimeograph, that modern marvel. |
hahahahh....thanks fingerdemon...you don't know how much i needed that... |
|
Back to top |
|
|
Dahak Registered User
Joined: 10 Feb 2002 Location: Rochester, NY and Windsor, CT Posts: 923
|
Posted: Mon May 06, 2002 3:38 pm Post subject: |
|
|
java > c++ |
|
Back to top |
|
|
Lin Sivvi Defiant Hero Registered User
Joined: 17 Jan 2002 Location: Some small boring city Posts: 1205
|
Posted: Mon May 06, 2002 3:40 pm Post subject: |
|
|
[start really n00b like question]
What does the * character in front of a variable do/
[/end really n00b like question]
Code: | #include <iostream.h>
int main()
{
int SomeVariable = 5;
cout << "SomeVariable: " << SomeVariable << "\n";
int *pVar = & SomeVariable;
*pVar = 9;
cout << "SomeVariable: " << *pVar << "\n";
return 0;
} |
I used that and compiled it... It's slightly different, but not by much. Also, what is the
Code: | int *pVar = & SomeVariable; |
for? I took it out before and just left int *pVar =9; and it compiled fine.
Then again this is coming from a ten year old kid who doesn't know the answer to the above question |
|
Back to top |
|
|
Computer Registered User
Joined: 15 Feb 2002 Location: Dah A T L Posts: 1336
|
Posted: Mon May 06, 2002 3:43 pm Post subject: |
|
|
It would help if you posted the errors also, I'll help ya if I can. _________________ "Don't be so humble - you are not that great."
|
|
Back to top |
|
|
Lin Sivvi Defiant Hero Registered User
Joined: 17 Jan 2002 Location: Some small boring city Posts: 1205
|
Posted: Mon May 06, 2002 3:47 pm Post subject: |
|
|
It says when I compile his code:
Quote: | C:\homework\main.cpp(10) : error C2040: 'pVar' : 'int' differs in levels of indirection from 'int *' |
So the code I had above basiclly just adds the *, and takes out the second int., fixing the problem. |
|
Back to top |
|
|
BitterBeerFace Registered User
Joined: 17 Jan 2002 Location: Mankato, MinneSNOWta Posts: 1416
|
Posted: Mon May 06, 2002 4:17 pm Post subject: |
|
|
Yes, you should only decalre int once, that's actually a command to initialize a vairable of "integer" type. Everytime you have "int" before something, it'll try to make a variable with that name, if you do it twice, it'll choke on compile.
First off, it'd be nice to know what the code is supposed to do.
It's been forever since I did any C++, but I think if you're just doing a little code to make a variable, and have it display the value of the variable, it'd be this:
#include <iostream.h>
int main()
{
int SomeVariable = 5;
cout << "SomeVariable: " << SomeVariable <<;
return 0;
}
That'd display "SomeVariable: 5"
Now then, if you're doing it to allow you to manipulate the variable by entering a value from the keyboard, you'll have to use the "cin >>" command to get a value from the keyboard.
I won't do the code for that, but hopefully that'll help ya get on the right track |
|
Back to top |
|
|
Enrico Registered User
Joined: 06 Jan 2002
Posts: 137
|
Posted: Mon May 06, 2002 5:03 pm Post subject: |
|
|
Hehehe, I dont do any C++ but i do fill my time with programming the TI-83 calculators. In my free time (school) i have made such classics as "GUESSNUM", and "DANCE", and let us not forget "MOOKA" hehehe, they use a psuedo basic language, right now i am working on "CIRCULAR"
My best program has about 150 lines and gets about 1fps... |
|
Back to top |
|
|
Lin Sivvi Defiant Hero Registered User
Joined: 17 Jan 2002 Location: Some small boring city Posts: 1205
|
Posted: Mon May 06, 2002 5:08 pm Post subject: |
|
|
lol! I program on the ti-83 too! I don't make complex stuff, but I make programs that solve stuff for me, I'm lazy Those calculators can handle assembly, I never bothered to learn it, but the assembly games are really neat.
Btw: I really don't know what the * in the variable name means, can someone tell me?
Well, this is enough of me carrying this post off topic, I gotta shutup |
|
Back to top |
|
|
|