Conversion Help Needed
Author |
Message |
P-Nut311
|
Posted: Thu Nov 25, 2004 10:09 pm Post subject: Conversion Help Needed |
|
|
I want a user to enter either a decimal or percentage, but the program must convert the percentages into decimals. How do I go about doing this? Whenever I attempt this, my program converts all numbers inputted. Can someone help me??
Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Thu Nov 25, 2004 10:12 pm Post subject: (No subject) |
|
|
Show us the code you have. |
|
|
|
|
|
P-Nut311
|
Posted: Fri Nov 26, 2004 2:33 pm Post subject: (No subject) |
|
|
Here's what I have so far...
code: |
%Investment program
var investment, interest : real
var term : int
var plan : string
locate (12, 29)
put "Cash Investment Program"
delay (5000)
cls
put "Please enter your cash investment: $" ..
get investment
cls
put "Please enter your interest rate: %" ..
get interest
if interest >= 0 then
interest := interest / 100
elsif interest >= 0.00 then
cls
end if
cls
|
I know that code under "get interest" is wrong. How do I make it so that when the user inputs a decimal, the program will leave the number alone, but when the user inputs a percentage, the program will convert it to a decimal?
Thanks |
|
|
|
|
|
Viper
|
Posted: Fri Nov 26, 2004 3:27 pm Post subject: (No subject) |
|
|
ok wut exactly is this program supposed 2 do |
|
|
|
|
|
Viper
|
Posted: Fri Nov 26, 2004 3:28 pm Post subject: (No subject) |
|
|
try that
var p:real
var n:real
var i:real
var A:real
put "how much money is in your bank?"..
get p
put "how many mounths will it be in there for?"..
get n
put "what is the intrest you are getting from the bank?"..
get i
A:= p *(1+i/12)**n
put " you Have",p,"$ in the bank,"
put "it will be in ther for",n,"mounths, at a ",i,"% intrest rate"
put "you should have" ,A, " when you take it out" |
|
|
|
|
|
P-Nut311
|
Posted: Fri Nov 26, 2004 5:36 pm Post subject: (No subject) |
|
|
The program is supposed to take the interest and if the user inputs a percentage, then the program must convert it into a decimal. If the user inputs a decimal, then the program should keep the decimal as it is. |
|
|
|
|
|
wtd
|
Posted: Fri Nov 26, 2004 7:01 pm Post subject: (No subject) |
|
|
P-Nut311 wrote: Here's what I have so far...
code: |
%Investment program
var investment, interest : real
var term : int
var plan : string
locate (12, 29)
put "Cash Investment Program"
delay (5000)
cls
put "Please enter your cash investment: $" ..
get investment
cls
put "Please enter your interest rate: %" ..
get interest
if interest >= 0 then
interest := interest / 100
elsif interest >= 0.00 then
cls
end if
cls
|
I know that code under "get interest" is wrong. How do I make it so that when the user inputs a decimal, the program will leave the number alone, but when the user inputs a percentage, the program will convert it to a decimal?
Thanks
By declaring "interest" as "real", you ensure that it will always be a decimal number. There's no need for conversion. |
|
|
|
|
|
con.focus
|
Posted: Sun Nov 28, 2004 9:19 pm Post subject: (No subject) |
|
|
Viper wrote: try that
var p:real
var n:real
var i:real
var A:real
put "how much money is in your bank?"..
get p
put "how many mounths will it be in there for?"..
get n
put "what is the intrest you are getting from the bank?"..
get i
A:= p *(1+i/12)**n
put " you Have",p,"$ in the bank,"
put "it will be in ther for",n,"mounths, at a ",i,"% intrest rate"
put "you should have" ,A, " when you take it out"
you should really give name to your variables espially in long code (make it ezer for ppl to read n figure out wut they mean or do |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Sun Nov 28, 2004 9:30 pm Post subject: (No subject) |
|
|
con.focus wrote: Viper wrote: try that
var p:real
var n:real
var i:real
var A:real
put "how much money is in your bank?"..
get p
put "how many mounths will it be in there for?"..
get n
put "what is the intrest you are getting from the bank?"..
get i
A:= p *(1+i/12)**n
put " you Have",p,"$ in the bank,"
put "it will be in ther for",n,"mounths, at a ",i,"% intrest rate"
put "you should have" ,A, " when you take it out"
you should really give meaningful name to your variables espially in long code (make it ezer for ppl to read n figure out wut they mean or do
Better. |
|
|
|
|
|
|
|