G
G
Gonlif2016-10-22 18:47:34
C++ / C#
Gonlif, 2016-10-22 18:47:34

How to convert array elements to variables?

Hello!
I need the opinion of experienced people who know how to solve my problem.
In general, we have the following
int a =2; intb=12; int c =4; int d=3;intx=5;
There is also an array
arr[3] ={ "x*b", "ac", "d+a"}
We need to convert values, for example "x*b", to the ready solution "x*b = 60".
I don't have enough knowledge to understand how to convert elements to variables.
I tried to pass values ​​to the function, but again the question is how to translate the elements into an array.

void foo (int arr[]) {
.....    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2016-10-22
@Nipheris

You need to do some simple parsing of the strings in the original array, and do the necessary calculations yourself. If the lines are of the same type, i.e. of the form xOy, where x and y are arguments, and O is an operation, then it is enough to split the string character by character and perform the O operation on the necessary arguments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question