Click here to Skip to main content
16,013,465 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to dynamically load GdiPlus.dll? Pin
Jun Du16-Jun-06 15:51
Jun Du16-Jun-06 15:51 
GeneralRe: How to dynamically load GdiPlus.dll? Pin
bob1697216-Jun-06 17:35
bob1697216-Jun-06 17:35 
GeneralRe: How to dynamically load GdiPlus.dll? Pin
James Brown18-Jun-06 22:20
James Brown18-Jun-06 22:20 
Questionenter key Pin
Tara1416-Jun-06 6:51
Tara1416-Jun-06 6:51 
AnswerRe: enter key Pin
Jun Du16-Jun-06 7:56
Jun Du16-Jun-06 7:56 
GeneralRe: enter key Pin
Tara1416-Jun-06 8:58
Tara1416-Jun-06 8:58 
GeneralRe: enter key Pin
Tara1416-Jun-06 9:27
Tara1416-Jun-06 9:27 
QuestionExcluding random choices (std c++) Pin
Peter Charlesworth16-Jun-06 5:01
Peter Charlesworth16-Jun-06 5:01 
Hey guys!

I have been working on my random combinor for a while now, and I want to take it to the next level.
The thing actually does this:

It has two arrays of strings, one being filled with names, the other being filled with activities that a person can do.

The program then randomly generates a number (1-9, where 9 is the amount of strings in both arrays) and displays the corresponding name/action.

E.g. "Kim" + " is working in the garden" = Kim is working in the garden.
(You can find the source underneath here, in case you need it)

Now, I want the program to EXCLUDE already used options.

For instance, in my exapmle, the name "Kim" and the activity " is working in the garden." will not be used anymore.

How can I do this? I thought of creating integers carrying or either the value 1 or 0 and when the program generates the random numbers it's going to check that value (0 means the name or activity has not yet been used)and turn it into 1 and proceed, or try another one when it's 1 until he finds one with 0.

But the problem is I don't know how to do this, unless by creating a lot of code, which is too ineffecient to me.

Does anyone have any ideas?

Thanks in advance!

random_activities.cpp<br />
#include < cstdlib ><br />
#include < ctime ><br />
#include < iostream ><br />
#include < string ><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
<br />
   string person[9] = {<br />
            "Jason",<br />
            "My best friend",<br />
            "Uncle Ben",<br />
            "Mark",<br />
            "Eva",<br />
            "Dad",<br />
            "My daughter",<br />
            "Deborah",<br />
            "That kid over there"};<br />
<br />
   string activity[9] = {<br />
            " is preparing a diner for two.",<br />
            " is playing a game of tennis with mum.",<br />
            " is making out with his/her girl/boyfriend.",<br />
            " is studying his geography exam.",<br />
            " is still sleeping.",<br />
            " is cruising on his motorcycle.",<br />
            " is shooting baskets in the garden.",<br />
            " is relaxing by the pool.",<br />
            " is coding a simple program in C++"};<br />
	<br />
    int a = 0;<br />
    int b;<br />
    int i;<br />
    int j;<br />
    const int N = 9;<br />
<br />
    cout << "Who is doing what? Find out with this program!\n";<br />
<br />
    cout << "Of how many persons would you like to know what they are doing?\nThey might be busy doing more things at a time, though!\n";  <br />
<br />
    cin >> b;<br />
<br />
    cout << endl;<br />
<br />
    srand( (unsigned)time( NULL ) );<br />
<br />
    while (a < b){<br />
<br />
    i = rand() % N;<br />
    j = rand() % N; <br />
    cout << person[i] << activity[j] << endl;  <br />
    a++;<br />
    	<br />
    }<br />
<br />
    cout << "\n\nNow you know a bit more about the people around you!\nCome back later, you hear!";<br />
<br />
    getchar();<br />
<br />
    return 0;<br />
 <br />
}

AnswerRe: Excluding random choices (std c++) Pin
capricious_00116-Jun-06 5:14
capricious_00116-Jun-06 5:14 
AnswerRe: Excluding random choices (std c++) [modified] Pin
Stephen Hewitt16-Jun-06 5:28
Stephen Hewitt16-Jun-06 5:28 
GeneralRe: Excluding random choices (std c++) Pin
Garth J Lancaster16-Jun-06 16:33
professionalGarth J Lancaster16-Jun-06 16:33 
AnswerRe: Excluding random choices (std c++) Pin
Chris Losinger16-Jun-06 6:35
professionalChris Losinger16-Jun-06 6:35 
Question'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 4:49
kitty516-Jun-06 4:49 
AnswerRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
Viorel.16-Jun-06 4:54
Viorel.16-Jun-06 4:54 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:02
kitty516-Jun-06 5:02 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
Viorel.16-Jun-06 5:13
Viorel.16-Jun-06 5:13 
QuestionRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:18
kitty516-Jun-06 5:18 
AnswerRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
Viorel.16-Jun-06 5:26
Viorel.16-Jun-06 5:26 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:48
kitty516-Jun-06 5:48 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' [modified] Pin
Viorel.16-Jun-06 5:56
Viorel.16-Jun-06 5:56 
Questionhow to send unicode text in XlTable Pin
bassel_z16-Jun-06 4:45
bassel_z16-Jun-06 4:45 
QuestionDynamically allocating static variables Pin
capricious_00116-Jun-06 3:54
capricious_00116-Jun-06 3:54 
AnswerRe: Dynamically allocating static variables Pin
Laxman Auti16-Jun-06 4:07
Laxman Auti16-Jun-06 4:07 
GeneralRe: Dynamically allocating static variables Pin
capricious_00116-Jun-06 4:17
capricious_00116-Jun-06 4:17 
AnswerRe: Dynamically allocating static variables Pin
Viorel.16-Jun-06 4:28
Viorel.16-Jun-06 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.