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:

Post by sirtom93 »

My friend and i were searching dreamcast homebrew games when we came accros this. That code does actualy work. I compile and it plays through fine..... If you want i could upload the .exe

Im 14 years of age. I have 2 years to do whatever i want so why not do c++,my cousin is a master at it and has a computing technology degree. He gave me the books.
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 »

Something must've gone wrong when you copied the code to your post then. Even if that did for some reason pass compilation it wouldn't work as you'd want.
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 »

Ok,here it is again.

Code: Select all

// 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
sirtom93
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 49
Joined: Sun Dec 09, 2007 9:34 am
Location: England.
Contact:

Post by sirtom93 »

Code: Select all


//Newrounds quiz by sirtom93.
#include <iostream>
#include <string>
using namespace std;

int main (){
    string creator;
    int score=0;
    cout<<"Hello and welcome to the newgrounds quiz v1.0.\nYou can testyour knowledge on how well you know newgrounds! ";
    cout<<"\n";
    //Questions start here.
    cout<<"question one: who is the creator of newgrounds";
    cin>>creator;
    
    //if and else loops statements.
    if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
                      cout<<"that is correct\n";
                      score+1;
                      }
    else{
         
         cout<<"that is incorrect \n\n";
         cout<<"Your final score is"<<score"\n";
         }
         
         system ("PAUSE");
         return (0);

}
    
The start of my Newgrounds quiz game.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

That's kewl--It's good to see you applying your knowledge and making something that's not right out of the book.

I haven't actually had time to look through the code--But does it work this far? If so, great job.

One thing that I did notice as I was scrolling through...Your braces are indented off. That's fine, it takes a while to learn good style, but try your best to keep it all lined up. See, this:

Code: Select all

     if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
                       cout<<"that is correct\n";
                      score+1;
                      }
    else{ 
should be

Code: Select all

  if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
                      cout<<"that is correct\n";
                      score+1;
    }
    else{ 
so that the end brace is lined up with the if statement.

Again, it's not an error or anything, but it prevents confusion and is good practice. Our Perl programmer for our game right now has complete shit style too, don't feel too bad. =P
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 »

You should tolower() your string input so that you won't have to check all cases. It's in cstring.h.
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 »

Ok thanks guys.
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 »

Im thinking of having a loop that goes back to the start if the user so desires. something like...

Code: Select all


char y/n = y

while (y/n ="n"){

// code 

cout<<"do you wish to continue: ";
cin>> y/n;
}


is that the best way of doing so?
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 »

Your while loop is still screwed up. You're setting it equal to "n," not testing for equality.

Use ==.
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 »

GyroVorbis wrote:Your while loop is still screwed up. You're setting it equal to "n," not testing for equality.

Use ==.

ahh i see. So == in a way compares the two and = makes it the same.
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 »

Yes. And while on the subject of that code snippet you can't have / in a variable name, that's division. You also can't compare strings with == (at least not C strings) like you're trying to. You can compare chars like that but "n" in this case is a null terminated string. To treat it as a char you do 'n' instead. Same applies to when you initialize your variable.
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:Yes. And while on the subject of that code snippet you can't have / in a variable name, that's division. You also can't compare strings with == (at least not C strings) like you're trying to. You can compare chars like that but "n" in this case is a null terminated string. To treat it as a char you do 'n' instead. Same applies to when you initialize your variable.
Got you. You may not see me round here that much as im going to to all out learning c++ over christmas and the internet distracts me.
User avatar
Kleithap
ES Web Developer
ES Web Developer
Posts: 324
Joined: Sat Jan 26, 2008 9:03 am
Location: Amsterdam

Post by Kleithap »

Just read all these post, and NO OFFENSE but: ROFL.

That's all, thank you very much.
User avatar
Ingulit
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Fri Feb 15, 2008 1:07 am
Location: Alabama
Contact:

Post by Ingulit »

Kleithap wrote:Just read all these post, and NO OFFENSE but: ROFL.

That's all, thank you very much.
^^^^^^^^^^^

If you're into C/C++ game programming, I'd recommend Sam's Teach Yourself C++ in 24 Hours as a C++ primer, and then Game Programming All-in-One, Third Edition to get you used to game code (and get you out of the console).

DISCLAIMER: I'm not trying to be rude with the following comment, so just hear me out.

The first game you posted, the one that took you a month? For most programmers who have a true chance in the field, such a program would've been their day 2 or 3 project, if even that late. You might want to reconsider this, for even with a ton of dedication, true game programming will require you to learn vast amounts of new things and to be able to apply them in a very short amount of time. I have no advice for how to do this, but you're going to have to learn faster if you are truly interested.

DISCLAIMER: I was not trying to be rude with the previous comment, so just heed what I said and consider it.
You guys ought to know me. WTB j00r physics h4x, kthx :)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Necromancy spooooooooooky.....
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply