Public Group

# Please someone help me out with converting array variable names

This topic is 4003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to use variable instead of numbers as infix. Say I have red*blue+green as infix, where these are red, blue, green are variables names representing each array columns for n*3 array. Get the corresponding numerical row values for each row and use it to substitute the variables in the input to get new infix. eg array[2][3]={34.5,13,21,11,16,9.55}where red,blue and green are the column names. Infix input : red+blue*green infix output:34.5+13*21 I haven't got any clue on how to go about this. Can someone help me out?

##### Share on other sites
Your question was kind of confusing, but is this what you are after?

#define RED   0#define GREEN 1#define BLUE  2double array[2][3] = { { 34.5, 13, 21, }, { 11, 16, 9.55 } };double output = array[RED][0] + array[BLUE][0] * array[GREEN][0];

##### Share on other sites
Quote:
 Original post by Mike.PopoloskiYour question was kind of confusing, but is this what you are after?*** Source Snippet Removed ***

You know general infix expression can be of the form 32*12+5. But instead of direct value input, I want to use column variable names of an array, then extract the corresponding elements to form a general infix expression. I have written the infix to postfix converter but it accepts the general form. What basically I'm trying to achieve is; if I input y=red*blue+green it will evaluate the expression for each row with coresponding elements of red, blue green in each row. Assuming column 1 in the array is red, column 2 is blue and column three is green. The output will be a string of sort 23*23.5+22 Assuming these are the corresponding values or a particular row which will then be passed to the infix-postfix function. Please assist me.

##### Share on other sites
so you want an expression (infix) to be of: y = mx + b to go to

##### Share on other sites
Quote:
 Original post by Alpha_ProgDesso you want an expression (infix) to be of: y = mx + b to go to

I don't intend to pass y to the infix-to-postfix converter only the right hand of the equalitity. Say a user inputs red+blue+green will give a string output of 23.4+22+33 assuming these are the corresponding values for row one in the array which I will now parse to my infix to postfix converter.I have done that bit of infix to postfix conversion but accepts it accepts expression of the form 12.5+63+12 or any other. Please someone should assist me!

[Edited by - Ben2k on August 1, 2007 3:50:19 PM]

##### Share on other sites
Please let someone help me out I'm stucked on this please

##### Share on other sites
Look into std::string namely its find and replace members, to replace all occurences of red, green and blue by their corresponding value.

##### Share on other sites
Quote:
 Original post by ToohrVykLook into std::string namely its find and replace members, to replace all occurences of red, green and blue by their corresponding value.

please I'm a beginner, I don't really understand or come across std::string. Could you please put me through?

##### Share on other sites
Quote:
Original post by Ben2k
Quote:
 Original post by ToohrVykLook into std::string namely its find and replace members, to replace all occurences of red, green and blue by their corresponding value.

please I'm a beginner, I don't really understand or come across std::string. Could you please put me through?

No offsense intended, but I smell some homework question. So: is it a homework question?

##### Share on other sites
Quote:
Original post by Emmanuel Deloget
Quote:
Original post by Ben2k
Quote:
 Original post by ToohrVykLook into std::string namely its find and replace members, to replace all occurences of red, green and blue by their corresponding value.

please I'm a beginner, I don't really understand or come across std::string. Could you please put me through?

No offsense intended, but I smell some homework question. So: is it a homework question?

I don't really blame you Emmanuel, do you know when I left school? I studied statistics and graduated 7years ago. I pray I don't come across people like you. Had it been I studied computer science, I wouldn't have been here to seek help and for you to smell rubbish. If you can't help me, why not hold your peace for men of good will to put me through.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631737
• Total Posts
3001944
×