Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to prompt a user to input an answer to a question. I want the question that pops up to have both text and numbers or strings. For example, if I ask the user to give a name to something in the first question, I want the next question to include that name as part of the question itself.

For example, I can prompt the user to name an element,

name=InputString["What is the name of your material?"]

I want the next input to be something like the question, "What is the molar weight of name?", where "name" is the input from the previous question. If the argument for Input[] were similar to Print[], it would look something like,

Input["What is the molar weight of ",name,"?"]

But this does not work because Input[] treats this as three different arguments, delimited by commas. Any thoughts?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You have to use StringJoin. In other cases you might also need to convert your variable into a string using ToString.

name=InputString["What is the name of your material?"]
Input["What is the molar weight of " <> ToString[name] <> "?"]
share|improve this answer
    
Thank you so much! I knew there was a simple solution that I would never figure out on my own. –  Benjamin Oct 9 '13 at 18:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.