|
-
February 10th, 2007, 09:33 PM
#1
Word Grabber
I want to write a C++ program that randomly selects one word from a list of words that i have somewhere in the source code.
I was wondering how to write this program, I am very new to programming and i was wondering if any one has a basic code like this, or if anyone can help me in anyway.
-
February 11th, 2007, 07:38 AM
#2
Re: Word Grabber
 Originally Posted by Simplex
I want to write a C++ program that randomly selects one word from a list of words that i have somewhere in the source code.
I was wondering how to write this program, I am very new to programming and i was wondering if any one has a basic code like this, or if anyone can help me in anyway.
Here try this simple example :
Code:
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> test;
test.push_back("Test0");
test.push_back("Test1");
test.push_back("Test2");
test.push_back("Test3");
test.push_back("Test4");
test.push_back("Test5");
test.push_back("Test6");
test.push_back("Test7");
test.push_back("Test8");
test.push_back("Test9");
size_t size = test.size();
srand(time(0));
int index = rand() % size;
cout<< "Random value: " << test[index].data();
return 0;
}
Good luck
Gili
Please use code tags [code] [/code]
We would change the world, but God won't give us the sourcecode.. 
Undocumented futures are fun and useful....
_________
Gili
-
February 12th, 2007, 06:10 AM
#3
Re: Word Grabber
My C++ Compiler said that had about 32 errors Why?
-
February 12th, 2007, 06:15 AM
#4
Re: Word Grabber
Well it would be useful to know which compiler you use
and more important, what this 32 Errors are in particular!
I would recommend you to read some basic stuff about c++
programming.
http://www.cplusplus.com/doc/tutorial/
http://www.cyberdiem.com/vin/learn.html
http://www.cprogramming.com/begin.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|