Page 1 of 3

Hey im sirtom93 and im learning c++

Posted: Sun Dec 09, 2007 9:51 am
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.

Posted: Sun Dec 09, 2007 10:46 am
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.

Posted: Sun Dec 09, 2007 10:49 am
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.

Posted: Sun Dec 09, 2007 10:59 am
by Tvspelsfreak
Try doing something text based. Learn about the stuff I mentioned.

Posted: Sun Dec 09, 2007 11:05 am
by sirtom93
Tvspelsfreak wrote:Try doing something text based. Learn about the stuff I mentioned.
Ok will do.

Posted: Sun Dec 09, 2007 5:43 pm
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.

Posted: Mon Dec 10, 2007 11:49 am
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.

Posted: Mon Dec 10, 2007 4:30 pm
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.

Posted: Tue Dec 11, 2007 10:38 am
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:

Posted: Tue Dec 11, 2007 12:02 pm
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);
}

Posted: Tue Dec 11, 2007 1:23 pm
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.

Posted: Tue Dec 11, 2007 1:34 pm
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...

Posted: Tue Dec 11, 2007 5:33 pm
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?

Posted: Tue Dec 11, 2007 6:04 pm
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.

Posted: Tue Dec 11, 2007 8:57 pm
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.