Just starting up
Moderator: Coders of Rage
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
Just starting up
Update on my guessing game
Now im going to do the random thingy that mar posted
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;
}
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
1/8th speed - 110mph
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
Just starting up
The Second Version of Guessing Game:
That would work right?
Now i am going to start a utility tool for a different game i am going to make
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;
}
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
1/8th speed - 110mph
- Falco Girgis
- 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
I think you forgot the openning bracket on your while() {.The Phantom wrote:The Second Version of Guessing Game:
That would work right?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; }
Now i am going to start a utility tool for a different game i am going to make
But I'm not positive what you want to do. But hey, looks great.
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
[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.
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.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
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.
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.
- Falco Girgis
- 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:
Maybe we should all start putting:
Then we could gather members of our rebellion and start some sort of ANTI-Ascii standard movement!
:!!!!:
Code: Select all
void main() {}
:!!!!:
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
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!
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
um i think this time its correct:
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
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;
}
Should i make another topic of this becuase its getting quite long
1/8th time- 14secs
1/8th speed - 110mph
1/8th speed - 110mph
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
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 â„¢?
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.
- Don Pwnious
- Chaos Rift Devotee
- Posts: 833
- Joined: Tue Jun 15, 2004 5:32 pm
- Location: on the streets wit my j23
- Contact:
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA