![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
the post from mocker is stupid as tempest pointed out. if you do not use srand with time or something pseudo-random you'll get the same shit every time. yeah it'll run...woo-fucking-hoo.
here is some neatly written code that modifies the original: #include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
srand (time(NULL));
int random_integer = rand()%10;
int x;
int guess;
while (1)
{
cout<<"Enter a number:";
cin>>guess;
if (guess < random_integer)
{
cout<<"Guess Higher"<<endl;
continue;
}
if (guess > random_integer)
{
cout<<"Guess Lower"<<endl;
continue;
}
if (guess == random_integer)
{
break;
}
}
cout<<"Congratulations,You WIN!"<<endl;
system("pause");
}
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#12 |
|
Expert Programmer
|
How random does the number actually have to be? lol.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#13 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5
![]() |
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#14 | |
|
Programmer
Join Date: Nov 2005
Location: Moseley, Birmingham, England, Earth
Posts: 51
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#15 |
|
Hobbyist Programmer
|
actualy no its not an inf loop it just does nothing at all.
ow an Ooble the int a = 10 |
|
|
|
|
|
#16 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
It's fine, but it isn't neat.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#17 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Someone needs to watch their semicolons -- both in terms of missing and extra.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#18 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Hacker, you're creating a whole new variable called a inside the loop every iteration that replaces the one outside the loop for its duration. Remove the "int".
BN, why not use ctime instead of time.h? This is C++ ya know. ![]() |
|
|
|
|
|
#19 | |
|
Professional Programmer
|
seeing as theres already a thread about random numbers made, ill ask here.. How do i assign srand() to a number inbetween something higher than 0? I have a header for producing random numbers in between the specified values, but then other poeple cant compile the program.. and thats not fair
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#20 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
srand just seeds the generator. Adjusting the range of the random numbers is another operation. One can scale it by various means. You need to know its normal range for your system and platform, of course.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|