Page 4 of 5

Posted: Mon Sep 06, 2004 9:23 am
by Don Pwnious
Coolie

Where di you hear this?

Just starting up

Posted: Mon Sep 06, 2004 1:54 pm
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

Just starting up

Posted: Mon Sep 06, 2004 1:59 pm
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

Re: Just starting up

Posted: Mon Sep 06, 2004 2:08 pm
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.

Posted: Mon Sep 06, 2004 2:10 pm
by Don Pwnious
ok ill fix it right away

Posted: Mon Sep 06, 2004 2:25 pm
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.

Posted: Mon Sep 06, 2004 2:35 pm
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;
}

Posted: Mon Sep 06, 2004 2:44 pm
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!
:!!!!:

Posted: Mon Sep 06, 2004 4:39 pm
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.

Posted: Mon Sep 06, 2004 5:40 pm
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.

Posted: Mon Sep 06, 2004 8:23 pm
by Don Pwnious
ohh ok i was about to use it

Posted: Tue Sep 07, 2004 3:24 pm
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

Posted: Tue Sep 07, 2004 3:55 pm
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 â„¢?

Posted: Tue Sep 07, 2004 4:04 pm
by Don Pwnious
oh sorry ok thanks for the tips and ill do that thread when i have a question

Posted: Thu Sep 09, 2004 7:09 pm
by MarauderIIC
Where arree youu unsticky button....