Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can anyone explain how to store a string as a variable?

  1. Dec 4, 2013 #1
    I don't have any big programs. I just write programs to get me through my math classes.
    But I want to have the output look pretty.
    Like one program I have is for my finance class.

    Code (Text):

    prompt p
    if p = 1
    then
    Prompt b,r,n,t
    r/100→x
    b/(1+x/n)^(n*t)→l
    disp l
    else
    Prompt b,r,n,t  
    r/100 → x  
    b*(x/n)/((1+x/n)^(n*t)-1) → m  
    disp m
     
    But what I want to do is instead of prompting p, I want to prompt "present value?"
    Then If present value = 1 then etc.
    It just looks neater if it prompts an entire string instead of one letter.
    So instead of prompting b,r,n,t it'll prompt
    "Ending Balance?"
    "Rate?"
    "Number of compounds?"
    "Time?"
    And then I can save those strings as variables.
    So ending balance → b
    Rate → r
    Number of compounds → n
    And then just have the rest of the program work with those letters instead of having to type out (rate/numberofcompounds)
    Every time I try to use strings instead of letters it always gives me a syntax error.
    Any help?
     
  2. jcsd
  3. Dec 4, 2013 #2

    jedishrfu

    Staff: Mentor

    Well you put a print statement in front of each prompt.
     
  4. Dec 4, 2013 #3

    Mark44

    Staff: Mentor

    breebreebran, you didn't say what kind of calculator you have, which would be useful information. It's possible that the prompt command has an optional first parameter of a string, like this:
    prompt "Present value? ", p

    If not, do as jedishrfu suggests, and print the string before executing the prompt.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Can anyone explain how to store a string as a variable?
  1. Can anyone explain? (Replies: 15)

Loading...