Author Topic: Programming Help! (C++)  (Read 476 times)

Offline TMRNetShark

  • Member
  • Posts: 4134
  • I thumps up my own youtube comments.
Programming Help! (C++)
« on: May 04, 2011, 08:56:08 PM »
Hello everyone, I need some help getting a program started (not really written for me, but more of a guideline of how to set it up). Here are the instructions..

(click to show/hide)

I do not know how to set up or do 3-4 to work properly. Any help would be great!

Offline Garret02

  • Member
  • Posts: 829
  • Death solves all problems - no man, no problem.
Re: Programming Help! (C++)
« Reply #1 on: May 04, 2011, 09:17:58 PM »
I think it should be like this
Code: [Select]
int x = 5;
int *px;
px = &x;
*px += 2;
cout<<*px<<endl;

Offline TMRNetShark

  • Member
  • Posts: 4134
  • I thumps up my own youtube comments.
Re: Programming Help! (C++)
« Reply #2 on: May 04, 2011, 09:25:11 PM »
I think it should be like this
Code: [Select]
int x = 5;
int *px;
px = &x;
*px += 2;
cout<<*px<<endl;

Now I can use this all under main, correct? No global variables or other functions, correct?

Offline Garret02

  • Member
  • Posts: 829
  • Death solves all problems - no man, no problem.
Re: Programming Help! (C++)
« Reply #3 on: May 04, 2011, 09:27:06 PM »
Yup, but remember to use either std:: before every cout and cin or type "using namespace std;" outside any function.

Offline Freedom Kira

  • Member
  • Posts: 4324
  • Rawr™.
Re: Programming Help! (C++)
« Reply #4 on: May 04, 2011, 09:32:44 PM »
That's pretty much right, though I would use
Code: [Select]
int *px = &x;
instead of
Code: [Select]
int *px;
px = &x;
because I'm lazy. And you should be, too. Save yourself as much typing as possible - it'll decrease the chance of bugs.

And you can put this code anywhere, though parts 3 and 4 won't work so well in the global domain.

The "using namespace std;" should come once in every .cpp file below all your includes (unsure of exact include syntax because different languages use different include syntax). For example:
Code: [Select]
#include iostream
using namespace std;

int main(void)
...

void function1(char x)
...

And for beginner-level C++, you should be putting the "using namespace std;" in pretty much every .cpp file.
« Last Edit: May 04, 2011, 09:35:50 PM by Freedom Kira »

Offline xShadow

  • Member
  • Posts: 1503
  • No
Re: Programming Help! (C++)
« Reply #5 on: May 04, 2011, 10:35:32 PM »
A function that just takes in a character? Interesting. Well, maybe if you had something that printed out the character input into some kind of image file via a predefined array of places to paint, and randomized colors (though you'd likely want an X/Y offset for that).

(click to show/hide)

Anyway, C++ seems to have some interesting stuff. I'll prolly be watching this thread because I wanna learn a bit more about what you can do differently in it, just for the heck of it (if the TC continues to ask questions here).

Cute, huh?

Offline TMRNetShark

  • Member
  • Posts: 4134
  • I thumps up my own youtube comments.
Re: Programming Help! (C++)
« Reply #6 on: May 05, 2011, 01:30:24 AM »
A function that just takes in a character? Interesting. Well, maybe if you had something that printed out the character input into some kind of image file via a predefined array of places to paint, and randomized colors (though you'd likely want an X/Y offset for that).

(click to show/hide)

Anyway, C++ seems to have some interesting stuff. I'll prolly be watching this thread because I wanna learn a bit more about what you can do differently in it, just for the heck of it (if the TC continues to ask questions here).

Dude, it's an elective class, I don't care about it... I can never understand why people want to do this as a job. It's just an hour of listening to the really good teacher... well... teach. Then 5 hours of banging my head against something because of goddamn errors. hahah

Offline Freedom Kira

  • Member
  • Posts: 4324
  • Rawr™.
Re: Programming Help! (C++)
« Reply #7 on: May 05, 2011, 03:23:04 AM »
Meh, if you're good at it, you're good at it. It pays good too.

A function that just takes in a character? Interesting.

Sure. A function can take in anything. It was just an example anyway.

(click to show/hide)

(click to show/hide)
« Last Edit: May 05, 2011, 03:28:21 AM by Freedom Kira »