Computer Science Canada

Conversion Help Needed

Author:  P-Nut311 [ 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

Author:  wtd [ Thu Nov 25, 2004 10:12 pm ]
Post subject: 

Show us the code you have.

Author:  P-Nut311 [ Fri Nov 26, 2004 2:33 pm ]
Post 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

Author:  Viper [ Fri Nov 26, 2004 3:27 pm ]
Post subject: 

ok wut exactly is this program supposed 2 do

Author:  Viper [ Fri Nov 26, 2004 3:28 pm ]
Post 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"

Author:  P-Nut311 [ Fri Nov 26, 2004 5:36 pm ]
Post 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.

Author:  wtd [ Fri Nov 26, 2004 7:01 pm ]
Post 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.

Author:  con.focus [ Sun Nov 28, 2004 9:19 pm ]
Post 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

Author:  wtd [ Sun Nov 28, 2004 9:30 pm ]
Post 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. Wink


: