Just starting up

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
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Coolie

Where di you hear this?
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Just starting up

Post by Don Pwnious »

Update on my guessing game

Code: Select all

 #include <iostream>
#include <time.h>
using namespace std;
	
int main() {
    //Seed the random generator
    srand( (unsigned)time( NULL ) );
    
    int number = rand() % 100;
    int guess;

    cout << "I am thinking of a number between 1 and 100" << endl;
    do {
    
	cout << "Enter your guess, please ";
        cin >> guess; 
    
        If (guess < number) 
       {
	    cout << "Too Low" << endl;
        }
        if (guess > number)
       {
	    cout << "Too High" << endl;
        }
    } while (guess != number);

    cout << "You win. Your mind power has increased. The answer was" << number<< endl;

    return 0;
}  
 
 
Now im going to do the random thingy that mar posted
Last edited by Don Pwnious on Mon Sep 06, 2004 1:54 pm, edited 2 times in total.
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Just starting up

Post by Don Pwnious »

The Second Version of Guessing Game:

Code: Select all

////////////Guessing game/////////////////
////////////by John Doan/////////////////
//Helped by friends on TheChaosRift.com//

#include <iostream>
#include <time.h>
using namespace std;
	
int main() {
    //Seed the random generator
    srand( (unsigned)time( NULL ) );
    
    int number;
    int newnum = rand(); //the power of random
    int guess;
    
    while(guess != number)//<~~~questioning is this how it goes??
    newnum = rand()
    number = rawnumber % 100
	
    cout << "I am thinking of a number between 1 and 100" << endl;
	cout << "Enter your guess, please ";
        cin >> guess; 
    
        If (guess == number) {
		cout << " Incredible, your mind power is beyond limits" << endl;
			break; //exit 
	}
	else {
		cout << HA HA!!!! you are inferior. Oh by the way, new number<< endl;
   	}

    } //while is closed
    
     return 0;
}  
That would work right?
Now i am going to start a utility tool for a different game i am going to make
Last edited by Don Pwnious on Mon Sep 06, 2004 1:59 pm, edited 2 times in total.
1/8th time- 14secs
1/8th speed - 110mph
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:

Re: Just starting up

Post by Falco Girgis »

The Phantom wrote:The Second Version of Guessing Game:

Code: Select all

////////////Guessing game/////////////////
////////////by John Doan/////////////////
//Helped by friends on TheChaosRift.com//

#include <iostream>
#include <time.h>
using namespace std;
	
int main() {
    //Seed the random generator
    srand( (unsigned)time( NULL ) );
    
    int number;
    int newnum = rand(); //the power of random
    int guess;
    
    while(guess != number)//<~~~questioning is this how it goes??
    newnum = rand()
    number = rawnumber % 100
	
    cout << "I am thinking of a number between 1 and 100" << endl;
	cout << "Enter your guess, please ";
        cin >> guess; 
    
        If (guess == number) {
		cout << " Incredible, your mind power is beyond limits" << endl;
			break; //exit 
	}
	else {
		cout << HA HA!!!! you are inferior. Oh by the way, new number<< endl;
   	}

    } //while is closed
    
     return 0;
}  
That would work right?
Now i am going to start a utility tool for a different game i am going to make
I think you forgot the openning bracket on your while() {.
But I'm not positive what you want to do. But hey, looks great.
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

ok ill fix it right away
1/8th time- 14secs
1/8th speed - 110mph
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

[paraphrase]Which is better, while or do[/paraphrase]

Neither. There's also a for loop. They're all different.
Do...while makes the loop run at least once.
While checks for condition before starting loop.
For declares a counter, loops while counter's condition is true, and can do something specific every loop, mainly to increment the counter.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

There's more wrong than just the missing bracket on while.
Try using the TAB key. I assume you're not, becaue there's no way you could end up with only three spaces on some lines if you weren't. :P
Your formatting is pretty.. awful.

And since I can't color things in code brackets, you'll have to deal with it until I change the phpBB source.

Code: Select all

int main() {
    //Seed the random generator
    srand( (unsigned)time( NULL ) );
   
    int number;
[color=red]//    int newnum;   [color=red]//you don't need to initialize it to a value here.
                        //it gets its value at the beginning of the loop.
                        //additionally, you don't even need this variable.
                        //you need either it or rawnumber and you use rawnumber
                        //w/o declaring it first.[/color]
    int guess;
    [color=red]unsigned int rawnumber;[/color]
   
    while(guess != number) [color=red]{[/color]
        [color=red]rawnumber[/color] = rand()[color=red];[/color]
        number = rawnumber % 100[color=red];[/color]
   
        cout << "I am thinking of a number between 1 and 100" << endl;
        cout << "Enter your guess, please ";
        cin >> guess;
   
        [color=red]i[/color]f (guess == number) {
            cout << " Incredible, your mind power is beyond limits" << endl;
            break; //exit [color=blue]the loop[/color]
        } else {
            cout << HA HA!!!! you are inferior. Oh by the way, new number[color=red]"[/color] << endl;
        }
    } //while is closed
   
    return 0;
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
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 »

Maybe we should all start putting:

Code: Select all

void main() {}
Then we could gather members of our rebellion and start some sort of ANTI-Ascii standard movement!
:!!!!:
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

Thanks Mar, I'll keep everthing you siad in mind.
And SS one word for you REBELLION
I think we should do that,

The book,"focus on SDL", I cant find it a borders so i am going to order it.
1/8th time- 14secs
1/8th speed - 110mph
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 »

Hey all, I've been on vacation so that is why my posts have sounded kinda shortish or something... I got to get on my Sister's Laptop once in a blue moon and check the forums.... ANYway, the reason I made a new version of the randome numbers thing was when I made the first one I didn't have a compiler so I just guessed. It turns out it didn't work right (the min and max didn't work). So I made the new one that DOES work.... This isn't really important, I just didn't want someone to accidently use the old one and get confused.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

ohh ok i was about to use it
1/8th time- 14secs
1/8th speed - 110mph
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

um i think this time its correct:

Code: Select all

/////////////Guessing game/////////////////
/////////////by John Doan/////////////////
//Helped by friends on TheChaosRift.com//

#include <iostream>
#include <time.h>
using namespace std;
	
int main() {
    //Seed the random generator
    srand( (unsigned)time( NULL ) );
    
    int number;
    int rawnumber; 
    int guess;
    
    while(guess != number) {

    rawnumber = rand();
    number = rawnumber % 100;

    cout << "I am thinking of a number between 1 and 100" << endl;
	cout << "Enter your guess, please ";
        cin >> guess; 
    
        if (guess == number) 
	{
		cout << " Incredible, your mind power is beyond limits" << endl;
			break; //exit loop 
	}
	else 
	{
		cout << "HA HA!!!! your inferior mind will explode soon. Oh by the way, new 

number" << endl;
   	}

    } //while is closed
    
     return 0;
}  
Umm my next project will hard and lemmings will probably help, if this is correct.

Should i make another topic of this becuase its getting quite long
1/8th time- 14secs
1/8th speed - 110mph
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Please, line everything up by using tab and not space.
At least rawnumber should be unsigned -- rand() only generates positive numbers, so there's no reason not to. number can stay int, because you might modify it eventually to make a negative number. guess should defininately stay int.

Since this thread is not really 'phantom programming' but 'tips?' then you should probably move to another thread.

You should fix this program up with some error checking (and line formatting :P). For example, what happens if the user enters "a" or "13498zfcx" or "-1.5" or "0 0 0" or "my name is darth vader!" or â„¢?
Last edited by MarauderIIC on Tue Sep 07, 2004 3:55 pm, edited 1 time in total.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Don Pwnious
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 833
Joined: Tue Jun 15, 2004 5:32 pm
Location: on the streets wit my j23
Contact:

Post by Don Pwnious »

oh sorry ok thanks for the tips and ill do that thread when i have a question
1/8th time- 14secs
1/8th speed - 110mph
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Where arree youu unsticky button....
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Locked