CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Word Grabber

  1. #1
    Join Date
    Feb 2007
    Posts
    2

    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.

  2. #2
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: Word Grabber

    Quote 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

  3. #3
    Join Date
    Feb 2007
    Posts
    2

    Re: Word Grabber

    My C++ Compiler said that had about 32 errors Why?

  4. #4
    Join Date
    Aug 2002
    Posts
    879

    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
  •  





Click Here to Expand Forum to Full Width

Featured