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

Username:   Password: 
 RegisterRegister   
 help with naming problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fartsniffer




PostPosted: 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.)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Clayton




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




PostPosted: 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.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: