Hey im sirtom93 and im learning c++

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Hey im sirtom93 and im learning c++

Post by sirtom93 »

Ive been learning c++ for about a months now and the code im most pleased with that i did all my self is the squaring code.

#include <iostream>
using namespace std;

int main()
{
int number;
int sqaure;
cout << "enter a number : " ;
cin >> number;
cout << "the number you entered is " << number;
cout << "\n\n";
cout << "the square of this number is ";
sqaure = number * number;
cout << sqaure;
cout << "\n\n";
system ("PAUSE");
return 0;
}


So im learning and i think ill try some opengl next.
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

How much do you know about control blocks, functions, structures, classes and such? Not that I wanna discourage you or something but squaring a number is far from doing something in OpenGL.
User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

Tvspelsfreak wrote:How much do you know about control blocks, functions, structures, classes and such? Not that I wanna discourage you or something but squaring a number is far from doing something in OpenGL.
I understand what your saying. What do you recomend i go onto then?

The fact is im quite pleased with what ive learnt and fully understand in just one month.
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

Try doing something text based. Learn about the stuff I mentioned.
User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

Tvspelsfreak wrote:Try doing something text based. Learn about the stuff I mentioned.
Ok will do.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

I'm not trying to be mean or anything... but this is the first thing I thought of when you said you were going to try OpenGL next.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

Yes. That is quite.... amusing. You didnt actualy contribute towards helping me progres my c++. Anyway im starting to get to a stage where i can write a simple high/low game straight of the top of my head.

I got the c++ bible that is very helpfull.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

You didnt actualy contribute towards helping me progres my c++.
Really? Are you sure? Just checking. Cause you know my purpose in life is to serve you. Just don't take me too seriously and you might come out alright.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

JS Lemming wrote:
You didnt actualy contribute towards helping me progres my c++.
Really? Are you sure? Just checking. Cause you know my purpose in life is to serve you. Just don't take me too seriously and you might come out alright.
I wouldnt take you seriously. Or would I?????



:butt:
User avatar
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

Here it is. My first ever game in c++. Higher and Lower.

// higher lower game by sirtom93.
#include <time>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
srand(time(NULL));
int guess;
int answer= rand() %10+1;
cout<< "welcome to the higher or lower game, by Sirtom93";
cout<< "\n";
cout<< "Please enter a number between 1 and 10: ";
cin>> guess;
cout<<"\n\n";
while ((guess>answer)||(guess<answer>answer){
cout <<"the number is to big,please try again";
cin >> guess;
}
if (guess<answer){
cout <<"the number is to small,please try again";
cin>> guess;
}
}
if (guess=answer);
cout<<"well done,you guessed right!";
cout<< "\n\n\n";
system ("PAUSE");
return (0);
}
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

It doesn't work. There's no way that you even tried to compile this.

Code: Select all

while ((guess>answer)||(guess<answer>answer)
That's wrong. Not only did you forget a parenthesis, but your logic is also off. Your while loop is also screwed, because it's not nesting the other ifs. The program flow doesn't work anything like you'd assume it would. Again, I recommend actually trying to run it, first.

Code: Select all

if (guess=answer); 
You're setting guess equal to answer, not checking equality.
User avatar
COAL
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Thu May 20, 2004 5:25 pm
Current Project: Adventures in Game Development
Favorite Gaming Platforms: N64, SNES, NES, Game Boy
Programming Language of Choice: C tic tac toe
Location: Salt Lake City, UT
Contact:

Post by COAL »

Uh... yeah dude, you might want to close off that while with a ')' after your conditionals, and also (guess<answer>answer) is kind of (ass)inine, as answer is never going to be greater than or less than itself... ass...
Res Novae
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

Um. Listen to your logic. Is one EVER greater than one? Is three EVERY greater than three? Is ANY number EVER greater than that same number? The answer to each of these is NO--And yes, that's exactly what you told the program to check for in your gnarled excuse of a while{}.

My advice to you is to avoid trying to memorize programs from the book you got (you say C++ superbible?) and actually learn to understand the logic behind it instead. Stop trying to recall a program from memory--Try tweaking them to do what you want, which requires you to understand it, and the rest should come naturally.

Btw, how old are you? C++ might actually be above your head a bit (judging by some of the posts you've made) so perhaps maybe you should start programming with something else? If your intent is games, perhaps try BlitzPlus (which I personally used for most of my 1st games)? Or Visual Basic?

Just suggestions. And out of curiosity, how'd you reach these forums? Was it from the development movies?
Tvspelsfreak
Chaos Rift Junior
Chaos Rift Junior
Posts: 272
Joined: Wed Sep 29, 2004 5:53 pm
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: C/C++
Location: Umeå, Sweden
Contact:

Post by Tvspelsfreak »

That program doesn't even compile.

What (guess<answer>answer) does is it performs the first comparison which has a boolean result (true/false, 0/1). That value is then used in the second comparison.

Code: Select all

if (guess=answer);
Not only is this wrong but it's totally unneccessary when you get the rest of the program working.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

Hey, Sirtom93, I apologize if we all come off as asses. I guess most of us think of you as the guy in way above his head--No offense.

Your first post when you said
So im learning and i think ill try some opengl next.
made you sound like a complete idiot, to be completely honest. That is like saying "Yeah, so I just learned how to add two numbers together--I think now I'm ready to learn Calculus," except, without proper capitalization or punctuation.

I'm sure most everybody here, who've been programming for years, laughed their asses off when they read that. Yes, it's very good that you're trying to learn. Just a bit of advice: Please, don't post like an idiot. It's more than obvious that you haven't got the slightest clue what OpenGL is, and until you do, please don't speak of it so lightly. "Yeah, I'm going to learn that next" makes you sound stupid. Also, perhaps proofreading your posts before submitting them would help prevent you from coming off as a little kid. Seriously.

I'd be more than willing to help you learn. We all would. Just stop acting like a little kid using mommas's computer.

Good job with your last program...But if you go and look back at your book that you probably copied it from, you did it wrong. Try compiling it, it's not going to work. If you need help figuring out why it doesn't work, (after reading all the other posts of the forum member pointing out the mistakes) feel free to ask.

Good luck.
Post Reply