Hi,
this is my first post so I apologise if I'm doing something wrong.
I got a problem calling a function in a class from lots of functions by generating a random number. What my idea of doing it is to generate a random number and then callin the function in like this: object.'function'+random();
but it doesn't work.
Please help me with this.
I made a simple code to show and ask what i need and what I mean:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "px.h"
#include <iostream>
usingnamespace std
void betkas::betkoks1(){
cout<<"something"<<endl;
}
void main(){
betkas pradedam; // we create an object here
int random = 1; //lets pretend this is a random number
pradedam. + 'betkoks' + random(); // this is the part I'm trying to call the function betkoks1
system("PAUSE"); // what am I doing wrong?
}
thats not what I need, maby I didn't specify what do I need corectly, I'll try it again :
this is something like a quiz program that gives you random questions and you need to state correct answers, of course it's only a fraction of the program
1 2 3 4 5 6
buvo:
Sleep(1000); //for random generation..
nr=pradedam.betkoks(); //calls a function that generates random
if ('kl'+nr == 1) goto buvo; // checks if the question was already asked, if it was then
//it goes to the buvo part to generate another random till it gets the random question that wasn't asked
pradedam.'klausimas'+nr (); //when we know the question wasn't asked we try to ask it but it doesn't work
becouse my assignment is to make it as simple as possible, and I think that my way is quite simple (primitive) but there's that problem - i don't know how to merge a word with a variable into a function name and then call that function succsessfuly. Is it possible ?