help with naming problem
Author |
Message |
fartsniffer
|
Posted: Thu Mar 22, 2007 11:40 am Post subject: help with naming problem |
|
|
The program is supposed to ask for a football team and the type of goal made and once done entering scores the program is supposed to print out the winner.
Since the program is in a loop and I do not know the names of the teams i used this code to try and make variables for the 2 team names. (code below)
var name : string
var name1 : string := "blah"
var name2 : string := "blah"
get name :*
if name not= name1 then
name1 := name
elsif name = name1 then
name2 := name
end if
For some reason every time a score is entered, the program thinks that it should add all scores to 'score1' which is the score for team1.
(I did not post the whole program with the scoring formula's because they work and I narrowed the problem down to the name if-statement above.) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Mar 22, 2007 2:37 pm Post subject: RE:help with naming problem |
|
|
I think you've got to start by making your variable names having some meaning.
Between name, name1, name2, "blah" and "blah", I have no idea what you are trying to do in your code. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Mar 22, 2007 3:15 pm Post subject: Re: help with naming problem |
|
|
If you're trying to do what I think you're trying to do, just have a custom type to hold the name of the team, and the score of the team. From there, you can just simply add the score to say, team 1. Some example code:
code: |
var teams : array 1 .. 2 of
record
name : string
score : int
end record
var goal : int
team (1).score := 0
put "Enter team 1's name"
get team (1).name
put "Enter team 1's goal"
get goal
team (1).score += 1
|
If you aren't sure about records or user-defined types, check out the Turing Walkthrough for the tutorial on them. |
|
|
|
|
![](images/spacer.gif) |
fartsniffer
|
Posted: Thu Mar 22, 2007 10:47 pm Post subject: Re: help with naming problem |
|
|
Thanks for the help on this one, I was stuck for hours. |
|
|
|
|
![](images/spacer.gif) |
|
|