Posted: Mon Sep 06, 2004 9:23 am
Coolie
Where di you hear this?
Where di you hear this?
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
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;
}
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;
}
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
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;
}
Code: Select all
void main() {}
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;
}