Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Conversion Help Needed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
P-Nut311




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: Thu Nov 25, 2004 10:12 pm   Post subject: (No subject)

Show us the code you have.
P-Nut311




PostPosted: 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




PostPosted: Fri Nov 26, 2004 3:27 pm   Post subject: (No subject)

ok wut exactly is this program supposed 2 do
Viper




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: 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. Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: