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

Username:   Password: 
 RegisterRegister   
 Need some help with basic coding
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aspire




PostPosted: Wed Sep 12, 2007 7:06 pm   Post subject: Need some help with basic coding

Hello, I am new to Compsci and new to Turing. I am in grade 10 and taking a course that is using turing.
Now I wanted to make a calculator and I was wondering how i can "call" on something for instance
I am finding it hard to explain.

Lets say someone enters in their level is 1. I want that levels amount to be subtracted from the total level and make it the "amountleft" variable.
The reason im having trouble is I want to do this on a large scale, (99 levels or so)

code:

var lvl1, lvl2, lvl3, lvl4 : int
var level : int
var total : int
var amountleft : int

total := 10000
lvl1 := 1000
lvl2 := 2000
lvl3 := 3000
lvl4 := 4000

put "Please enter your level"
get level

amountleft := (level - (total level amount))


I am having trouble explaining this. So if anyone is willing to help me, I can PM them the real code and see if you can help. The only reason why I didnt want to post it is because its quite long.
Heres my contact info if you can help

MSN: Beat-Of-Aspire@hotmail.com (Really only use this one)
AIM: beckershoes1
Yahoo: jamiechese@yahoo.ca
xfire: aspire0


Thanks to anyone who can get me going in the right direction!!
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Sep 12, 2007 7:29 pm   Post subject: RE:Need some help with basic coding

It sounds like you are looking for an array.

We have an excellent walkthrough for Turing

Clayton has done something useful, and wrote up some good material on Arrays. You should probably limit yourself just to the first part of that tutorial for now.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Clayton




PostPosted: Wed Sep 12, 2007 7:34 pm   Post subject: RE:Need some help with basic coding

Tony wrote:
Clayton has done something useful...


Ouch...

Although Tony is right, arrays do indeed sound like what you are looking for.

As well, welcome to CompSci.ca! If you have any more questions, feel free to ask!
aspire




PostPosted: Wed Sep 12, 2007 7:45 pm   Post subject: RE:Need some help with basic coding

Thanks for the help Very Happy Lol.

I will see if it works.

Thanks again
Tony




PostPosted: Wed Sep 12, 2007 7:52 pm   Post subject: RE:Need some help with basic coding

Oh come on Clayton! I'm trying to give you a complement, and even linking to something that you wrote! Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
aspire




PostPosted: Wed Sep 12, 2007 7:58 pm   Post subject: RE:Need some help with basic coding

I am confused.
Ok so I have the array. I still dont understand how to "connect" it to the levels

lets say someone enters level 2

then i want it to subtract

(amount of the level - total)

I read the tutorial, I just am not sure how or if it applies to what im trying to get at >_<
Clayton




PostPosted: Wed Sep 12, 2007 8:00 pm   Post subject: RE:Need some help with basic coding

Alright, fair enough. Thanks Wink
CodeMonkey2000




PostPosted: Wed Sep 12, 2007 8:09 pm   Post subject: RE:Need some help with basic coding

Have an array of lvls, take the level that the user inputs and access that level with: lvl(level)
Sponsor
Sponsor
Sponsor
sponsor
aspire




PostPosted: Wed Sep 12, 2007 8:18 pm   Post subject: RE:Need some help with basic coding

Alright. Well I am really lost. So I will just post the whole thing. I am making it for a game my brother plays. Just thought it would be some good experience to practice with turing
So lets say if someone enters 80 i want it to subtract "level 80's" amount from the total amount.

Here is the stuff I currently have.

code:

var array_1 : array 1..99 of int
var fletching : int
var levelsleft : int
var expleft: int
var alevel : int
var totalexp :  int
var lvl1, lvl2 ,lvl3 ,lvl4 ,lvl5 ,lvl6 ,lvl7 ,lvl8 ,lvl9 ,lvl10 ,lvl11 ,lvl12 ,lvl13, lvl14 ,lvl15 ,lvl16
 ,lvl17 ,lvl18 ,lvl19 ,lvl20 ,lvl21 ,lvl22 ,lvl23 ,lvl24 ,lvl25 ,lvl26 ,lvl27 ,lvl28 ,lvl29 ,lvl30 ,lvl31
 ,lvl32 ,lvl33 ,lvl34 ,lvl35 ,lvl36 ,lvl37 ,lvl38 ,lvl39 ,lvl40 ,lvl41 ,lvl42 ,lvl43 ,lvl44 ,lvl45 ,lvl46
 ,lvl47 ,lvl48 ,lvl49 ,lvl50 ,lvl51 ,lvl52 ,lvl53 ,lvl54 ,lvl55 ,lvl56 ,lvl57 ,lvl58 ,lvl59 ,lvl60 ,lvl61
 ,lvl62 ,lvl63 ,lvl64 ,lvl65 ,lvl66 ,lvl67 ,lvl68 ,lvl69 ,lvl70 ,lvl71 ,lvl72 ,lvl73 ,lvl74 ,lvl75 ,lvl76
 ,lvl77 ,lvl78 ,lvl79 ,lvl80 ,lvl81 ,lvl82 ,lvl83 ,lvl84 ,lvl85 ,lvl86 ,lvl87 ,lvl88 ,lvl89 ,lvl90 ,lvl91
 ,lvl92 ,lvl93 ,lvl94 ,lvl95 ,lvl96 ,lvl97 ,lvl98 ,lvl99 : int
 
totalexp := 13034431

lvl1 := 0
lvl2 := 83
lvl3 := 174
lvl4 := 276
lvl5 := 388
lvl6 := 512
lvl7 := 650
lvl8 := 801
lvl9 := 969
lvl10 := 1154
lvl11 := 1358
lvl12 := 1584
lvl13 := 1833
lvl14 := 2107
lvl15 := 2411
lvl16 := 2746
lvl17 := 3115
lvl18 := 3523
lvl19 := 3973
lvl20 := 4470
lvl21 := 5018
lvl22 := 5624
lvl23 := 6291
lvl24 := 7058
lvl25 := 7842
lvl26 := 8740
lvl27 := 9730
lvl28 := 10824
lvl29 := 12031
lvl30 := 13363
lvl31 := 14833
lvl32 := 16456
lvl33 := 18247
lvl34 := 20224
lvl35 := 22406
lvl36 := 24815
lvl37 := 27473
lvl38 := 30408
lvl39 := 33648
lvl40 := 37224
lvl41 := 41171
lvl42 := 45529
lvl43 := 50339
lvl44 := 55649
lvl45 := 61512
lvl46 := 67983
lvl47 := 75127
lvl48 := 83014
lvl49 := 91721
lvl50 := 101333
lvl51 := 111945
lvl52 := 123660
lvl53 := 136594
lvl54 := 150872
lvl55 := 166636
lvl56 := 184040
lvl57 := 203254
lvl58 := 224466
lvl59 := 247886
lvl60 := 273742
lvl61 := 302288
lvl62 := 333804
lvl63 := 368599
lvl64 := 407015
lvl65 := 449428
lvl66 := 496254
lvl67 := 547953
lvl68 := 605032
lvl69 := 668051
lvl70 := 737627
lvl71 := 814445
lvl72 := 899257
lvl73 := 992895
lvl74 := 1096278
lvl75 := 1210421
lvl76 := 1336443
lvl77 := 1475581
lvl78 := 1629200
lvl79 := 1798808
lvl80 := 1986068
lvl81 := 2192818
lvl82 := 2421087
lvl83 := 2673114
lvl84 := 2951373
lvl85 := 3258594
lvl86 := 3597792
lvl87 := 3972294
lvl88 := 4385776
lvl89 := 4842295
lvl90 := 5346332
lvl91 := 5902831
lvl92 := 6517253
lvl93 := 7195629
lvl94 := 7944614
lvl95 := 8771558
lvl96 := 9684577
lvl97 := 10692629
lvl98 := 11805606
lvl99 := 13034431


put "Please enter your fletching level: "
get fletching

levelsleft := (99 - fletching)

put "The amount of levels you have left to 99 is:  ", levelsleft

put "What level do you want to acheive: "
get alevel

expleft := (lvl-totalexp)

put "You have this much XP left: ", expleft
Tony




PostPosted: Wed Sep 12, 2007 11:33 pm   Post subject: RE:Need some help with basic coding

Well arrays are considered to be a more "advanced" concept, usually taught later in the year.

The basic idea is that you can do things like
Turing:

var collection : array 1..2 of int := init (10, 20)

puts "the value of collection's item #2 is: ", collection(2)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Nick




PostPosted: Thu Sep 13, 2007 6:31 am   Post subject: RE:Need some help with basic coding

ahaha i recognise that code anywheere thats a runescape level calculator (dont worry ppl i quit a while ago just have friends who still play... and a cousin) anyways it doesnt quite seem like u got arrays down yet... instead of making 99 diffrent varibles for each level just make a
Turing:
var lvl:array 1..99 of int

then to set them just put
Turing:
lvl(1):=0
lvl(2):=86
etc...
HeavenAgain




PostPosted: Thu Sep 13, 2007 11:19 am   Post subject: RE:Need some help with basic coding

normally for assigning array variables, we like to use a loop, instead of typing all the array's name again

bad example would be, in this case:
lvl (1) := 0
lvl (2) := 86.... etc

if thats the case, then whats the point of using an array, it will be just the same to type up all the var lvl_1 blah blah blah.

so try to find the increasing value, and do it in one small loop (unless its too complicated...)
CodeMonkey2000




PostPosted: Thu Sep 13, 2007 11:58 am   Post subject: RE:Need some help with basic coding

0_o

aspire, seriously re-read Clayton's array tutorial and LEARN from it.
aspire




PostPosted: Thu Sep 13, 2007 12:53 pm   Post subject: RE:Need some help with basic coding

Uh, codemonkey. I did read it. I was half alseep though last night, so I think i probably didnt totally let the info seep in. I have only been doing turing for about 1 week in school, so yeah I admit it, I am slow.

I didnt want to agitate you or anything. But really, thanks for the current help everyone has given

Well, I was messing around with it at school. I didnt get very far but I did set the arrays properly, (I think)
Teacher told me I cant subtract arrays. I will be reading that tutorial over a few times when I get home too so, please bear with me.

code:
var lvl : array 1 .. 99 of int
var fun : int
var levelsleft : int
var expleft : int
var alevel : int
var TEXP : int

TEXP := 13034431

lvl(1) := 0
lvl(2) := 83
lvl(3) := 174
lvl(4) := 276
lvl(5) := 388
lvl(6) := 512
lvl(7) := 650
lvl(8) := 801
lvl(9) := 969
lvl(10) := 1154
lvl(11) := 1358
lvl(12) := 1584
lvl(13) := 1833
lvl(14) := 2107
lvl(15) := 2411
lvl(16) := 2746
lvl(17) := 3115
lvl(18) := 3523
lvl(19) := 3973
lvl(20) := 4470
lvl(21) := 5018
lvl(22) := 5624
lvl(23) := 6291
lvl(24) := 7058
lvl(25) := 7842
lvl(26) := 8740
lvl(27) := 9730
lvl(28) := 10824
lvl(29) := 12031
lvl(30) := 13363
lvl(31) := 14833
lvl(32) := 16456
lvl(33) := 18247
lvl(34) := 20224
lvl(35) := 22406
lvl(36) := 24815
lvl(37) := 27473
lvl(38) := 30408
lvl(39) := 33648
lvl(40) := 37224
lvl(41) := 41171
lvl(42) := 45529
lvl(43) := 50339
lvl(44) := 55649
lvl(45) := 61512
lvl(46) := 67983
lvl(47) := 75127
lvl(48) := 83014
lvl(49) := 91721
lvl(50) := 101333
lvl(51) := 111945
lvl(52) := 123660
lvl(53) := 136594
lvl(54) := 150872
lvl(55) := 166636
lvl(56) := 184040
lvl(57) := 203254
lvl(58) := 224466
lvl(59) := 247886
lvl(60) := 273742
lvl(61) := 302288
lvl(62) := 333804
lvl(63) := 368599
lvl(64) := 407015
lvl(65) := 449428
lvl(66) := 496254
lvl(67) := 547953
lvl(68) := 605032
lvl(69) := 668051
lvl(70) := 737627
lvl(71) := 814445
lvl(72) := 899257
lvl(73) := 992895
lvl(74) := 1096278
lvl(75) := 1210421
lvl(76) := 1336443
lvl(77) := 1475581
lvl(78) := 1629200
lvl(79) := 1798808
lvl(80) := 1986068
lvl(81) := 2192818
lvl(82) := 2421087
lvl(83) := 2673114
lvl(84) := 2951373
lvl(85) := 3258594
lvl(86) := 3597792
lvl(87) := 3972294
lvl(88) := 4385776
lvl(89) := 4842295
lvl(90) := 5346332
lvl(91) := 5902831
lvl(92) := 6517253
lvl(93) := 7195629
lvl(94) := 7944614
lvl(95) := 8771558
lvl(96) := 9684577
lvl(97) := 10692629
lvl(98) := 11805606
lvl(99) := 13034431


put "Please enter your fun level: "
get fun

levelsleft := (99 - fun)

put "The amount of levels you have left to 99 is:  ", levelsleft

put "What level do you want to acheive: "
get alevel

(Somehow subtract the lvl() that the user has entered, get the corresponding array number and subtract it from the TEXP)

put "You have this much XP left: ",
Nick




PostPosted: Thu Sep 13, 2007 2:17 pm   Post subject: RE:Need some help with basic coding

dude u almost had it... with just a couple adjustments i completed your code here it is

Turing:
var lvl : array 1 .. 99 of int
var fun : int
var levelsleft : int
var expleft : int
var alevel : int
var TEXP : int

TEXP := 13034431

lvl (1) := 0
lvl (2) := 83
lvl (3) := 174
lvl (4) := 276
lvl (5) := 388
lvl (6) := 512
lvl (7) := 650
lvl (8) := 801
lvl (9) := 969
lvl (10) := 1154
lvl (11) := 1358
lvl (12) := 1584
lvl (13) := 1833
lvl (14) := 2107
lvl (15) := 2411
lvl (16) := 2746
lvl (17) := 3115
lvl (18) := 3523
lvl (19) := 3973
lvl (20) := 4470
lvl (21) := 5018
lvl (22) := 5624
lvl (23) := 6291
lvl (24) := 7058
lvl (25) := 7842
lvl (26) := 8740
lvl (27) := 9730
lvl (28) := 10824
lvl (29) := 12031
lvl (30) := 13363
lvl (31) := 14833
lvl (32) := 16456
lvl (33) := 18247
lvl (34) := 20224
lvl (35) := 22406
lvl (36) := 24815
lvl (37) := 27473
lvl (38) := 30408
lvl (39) := 33648
lvl (40) := 37224
lvl (41) := 41171
lvl (42) := 45529
lvl (43) := 50339
lvl (44) := 55649
lvl (45) := 61512
lvl (46) := 67983
lvl (47) := 75127
lvl (48) := 83014
lvl (49) := 91721
lvl (50) := 101333
lvl (51) := 111945
lvl (52) := 123660
lvl (53) := 136594
lvl (54) := 150872
lvl (55) := 166636
lvl (56) := 184040
lvl (57) := 203254
lvl (58) := 224466
lvl (59) := 247886
lvl (60) := 273742
lvl (61) := 302288
lvl (62) := 333804
lvl (63) := 368599
lvl (64) := 407015
lvl (65) := 449428
lvl (66) := 496254
lvl (67) := 547953
lvl (68) := 605032
lvl (69) := 668051
lvl (70) := 737627
lvl (71) := 814445
lvl (72) := 899257
lvl (73) := 992895
lvl (74) := 1096278
lvl (75) := 1210421
lvl (76) := 1336443
lvl (77) := 1475581
lvl (78) := 1629200
lvl (79) := 1798808
lvl (80) := 1986068
lvl (81) := 2192818
lvl (82) := 2421087
lvl (83) := 2673114
lvl (84) := 2951373
lvl (85) := 3258594
lvl (86) := 3597792
lvl (87) := 3972294
lvl (88) := 4385776
lvl (89) := 4842295
lvl (90) := 5346332
lvl (91) := 5902831
lvl (92) := 6517253
lvl (93) := 7195629
lvl (94) := 7944614
lvl (95) := 8771558
lvl (96) := 9684577
lvl (97) := 10692629
lvl (98) := 11805606
lvl (99) := 13034431


put "Please enter your fun level: "
get fun

levelsleft := (99 - fun)

put "The amount of levels you have left to 99 is:  ", levelsleft

put "What level do you want to acheive: "
get alevel

%(Somehow subtract the lvl() that the user has entered, get the corresponding array number and subtract it from the TEXP)

put "You have this much XP left: ", lvl (alevel) - lvl (fun)


now just look over the change (last line) and see where u went wrong... for a week in ur pretty good keep ur chiin up and keep on trying
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: