C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I'm uhh... Begining this C++ stuff. Need some help here. Just making a little thingy to see what I know. ...
-
10-19-2006, 06:15 PM #1411QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
I'm uhh... Begining this C++ stuff. Need some help here. Just making a little thingy to see what I know. :\
#include <iostream.h>
int main() {
int theYear = 2006;
return 0;
}
int main() {
int myBirthYear = 1992;
return 0;
}
int main() {
int myAge = << theYear - myBirthYear << endl;
cout << "My age is " << myAge << endl;
return 0;
}
-= Double Post =-
Oh. And I don't understand the compiler errors on Dev-Cpp... :\
Geändert von Cheez Pirate (10-19-2006 um 06:15 PM Uhr) Grund: Automerged Doublepost
-
10-19-2006, 06:20 PM #1412I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I know nothing of C++. But from coding C on the PSP, something tells me it should be more like that.Code:#include <iostream.h> int main() { int theYear = 2006; int myBirthYear = 1992; int myAge = << theYear - myBirthYear << endl; cout << "My age is " << myAge << endl; return 0; }
-
10-19-2006, 06:24 PM #1413QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Wow. I just realized how stupid I am. Even though it doesn't work. Need more help please lol.
-= Double Post =-
I think my only problem is subtracting. I didn't know how so I took a guess. Someone tell me how to subtract?Geändert von Cheez Pirate (10-19-2006 um 06:24 PM Uhr) Grund: Automerged Doublepost
-
10-19-2006, 06:25 PM #1414Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
its ok. my first program in C was similar to this:
Zitat von Cheez Pirate
Code:int 5; void main(x) { print("what is int?" " int is int") end }
BTW, i got my problem fixed.--------------------------------------------------------------------------------------
-
10-19-2006, 06:29 PM #1415I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Try that.Code:#include <iostream> using namespace std; int main () { int currentYear, myBirthYear; int myAge; currentYear = 2006; myBirthYear = 1992; myAge = currentYear - myBirthYear; cout << myAge; return 0; }
-
10-19-2006, 06:30 PM #1416QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Oh. Ok, hang on. By the way. What's the difference between C, and C++?
-
10-19-2006, 06:32 PM #1417I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I edited the code because I seen a mistake. So if it doesn't work, try the new code. And the only only difference between them is syntax. It's the only difference between all languages. They all work the same way. You just have to know the 'words' the language should be written in.
Zitat von Cheez Pirate

-
10-19-2006, 06:36 PM #1418QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Thanks. That worked! And I understand it too. Thanks a lot!
-
10-19-2006, 06:37 PM #1419I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I think the problem was that you forgot using namespace std;. But as I said, I'm no expert.

-
10-19-2006, 06:38 PM #1420QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
:o Also. Is there a main loop? I run it and it disapears right away.
-
10-19-2006, 06:40 PM #1421I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I don't know. I just modified this code from a tutorial.
// operating with variables
#include <iostream>
using namespace std;
int main ()
{
// declaring variables:
int a, b;
int result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
return 0;
}
-
10-19-2006, 06:41 PM #1422Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Cheez Pirate
do this:
that basically says, "wait forever." :)Code:int main() { // your main function // while (1) { // the printing stuff here// sceDisplayWaitVblankStart(); flipScreen(); } sceKernelSleepThread(); return 0; }--------------------------------------------------------------------------------------
-
10-19-2006, 06:42 PM #1423QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Ok. Guess I gotta get rid of "return 0;"
-= Double Post =-
Or that lol.
Geändert von Cheez Pirate (10-19-2006 um 06:42 PM Uhr) Grund: Automerged Doublepost
-
10-19-2006, 06:43 PM #1424Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
propel, stop leading him towards computer C++. i understand that your trying to help, but comp. and psp stuff is very different. for one, in psp, you dont need to put:
Zitat von Propel
and you need a loop, just like in lua.Code:using namespace std
--------------------------------------------------------------------------------------
-
10-19-2006, 06:44 PM #1425I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
He's coding for the PC.
Zitat von Grimfate126

-
10-19-2006, 06:45 PM #1426Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Propel
then why is it in this section?--------------------------------------------------------------------------------------
-
10-19-2006, 06:46 PM #1427I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Because it's the C/C++ Development thread. Maybe he's practicing coding for the PSP.
Zitat von Grimfate126

-
10-19-2006, 06:49 PM #1428QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Ya. I'm using it on both.
-= Double Post =-
Like learning both at the same time. Functions for PSP, and comp.Geändert von Cheez Pirate (10-19-2006 um 06:49 PM Uhr) Grund: Automerged Doublepost
-
10-19-2006, 06:50 PM #1429Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ok. im just warning you that you may get confused. try to learn one thing. then use it for another. (ur choice.)
Zitat von Cheez Pirate
--------------------------------------------------------------------------------------
-
10-19-2006, 06:54 PM #1430QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
lol ok. Well I saved the PSP main loop in a txt doc. Now I need the loop for the computer if there is one. Coz when I run it. It still shuts itself off after like a milisecond.
-
10-19-2006, 07:03 PM #1431Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von Cheez Pirate
i dont know much about comp c++. use google.--------------------------------------------------------------------------------------
-
10-19-2006, 11:30 PM #1432AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Just put system("PAUSE"); right before the return 0;
Oh, and you don't have to put using namespace std; you simply can write std::cout, std::cin ... instead.
-
10-19-2006, 11:37 PM #1433QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
No Idea, but tell him this: < !!
Zitat von Bronx
Seriuosly? Why is that?
Zitat von homer
-
10-20-2006, 01:35 AM #1434QJ Gamer Green

- Registriert seit
- May 2006
- Ort
- Programming or Farming Mudkips
- Beiträge
- 657
- Points
- 6.920
- Level
- 54
- Downloads
- 0
- Uploads
- 0
I wouldn't do that. That's just settign yourself up towards failure. Just learn c. And I really wouldn't recommend learning on the pc, seeing as it's actually easier to code on the psp then the pc. :P
Zitat von Cheez Pirate
Current Project: Citrus
-
10-20-2006, 03:33 AM #1435QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Zettablade: That is a matter of opinion. I find it a hell of a lot easier to program something with C++ then C. Strip away all the libraries and I pick C++ with classes, strict type safety, const correctness and template metaprogramming over C structs and macros any day of the week.
I also disagree about learning straight away on a PSP/DS/any hardware platform. Trying to get your head round the SDK/toolchain AND learning how to program at the same time can be extremely difficult to do for a new programmer. However, I agree that you should only develop for one platform then move on to the next.Geändert von yaustar (10-20-2006 um 04:28 AM Uhr)
-
10-20-2006, 05:02 AM #1436AKA Homer

- Registriert seit
- Jan 2006
- Ort
- Sweden
- Beiträge
- 1.779
- Points
- 12.596
- Level
- 73
- Downloads
- 0
- Uploads
- 0
I think that's what youresam tried to tell you too.
Zitat von Lukeson
The reason it's faster is because it doesn't have to go through as many pixels. Just think about it, the large image contains 480*272 pixels, while the arrows contain like 5*5+5*5+5*5 ...
-
10-20-2006, 05:18 AM #1437QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
i c... (even though the image is only 5*260, still true)
-
10-20-2006, 06:15 AM #1438QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
In addition, you are using less memory to store the image of one arrow.
-
10-20-2006, 06:58 AM #1439QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Getting an error google doesn't have an answer for:
I got a round fuction from http://www.cs.tut.fi/~jkorpela/round.html . I included <limits.h> as written on the page. The error I get is
The code ismain.c:(.text+0x2c): undefined reference to `assert'
main.c:(.text+0x4c): undefined reference to `assert'
Code:long round(double x) { assert(x >= LONG_MIN-0.5); assert(x <= LONG_MAX+0.5); if (x >= 0) return (long) (x+0.5); return (long) (x-0.5); }
-
10-20-2006, 07:02 AM #1440QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You need to #include <assert.h> where you use the function assert. (#include <cassert> if you are using C++).


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum