From: Samantha Date: 2007-03-01T12:02:36+09:00 Subject: Re: Stepping out on a Limb - some very ugly code ------=_Part_54709_23592294.1172718143523 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline After taking several suggestions, I've come up with 91 lines of code (including blank lines because I like organizing things). I have a few issues in certain areas of the code... I'll post all 91 lines (including lines intentionally left blank), and explain what I'm having go wrong... I'm just not getting it, but maybe I don't quite understand certain things... (probably, not maybe ;) (And please excuse the rude prompts - I'm not really this rude, nor would I write such a rude program for deployment into the world.) #ResumeBuilder.rb #This is the section that defines a prompt. def prompt(string) puts(string) gets.chomp end #This section defines a prompt that requires a yes or no answer. def boolean_prompt(string) prompt("#{string} (yes/no)").downcase == "yes" end #Main program logic for User Identity puts("Welcome to Resume Builder v.1") first_name = prompt("Please enter your first name: ").capitalize! last_name = prompt("Please enter your last name: ").capitalize! #This verifies that the user is who they said they were. correct = boolean_prompt("So, your name is #{first_name} #{last_name}?") if correct puts("Great! Let's get started, #{first_name}!") else puts("Please come back when you know who you are.") exit 1 end ------------When I get to this point, if I typed in the answers to the prompts with the first letter capitalized (ie Samantha for the first name), when the program verifies what I typed whatever values it is verifying, as blank... #now we get the address information of the user street_number = prompt("Please enter your street number: ") street_name = prompt("Please enter your street name: ").capitalize! city_name = prompt("Please enter your city name: ").capitalize! state_name = prompt("Please enter the state you live in: ").upcase! zip_code = prompt("Please enter your zip code: ") phone_number = prompt("Please enter your phone number in the following format: (999) 999-9999: ") email_address = prompt("Please enter your email address in the follwoing format: name@domain.com: ") correct = boolean_prompt("Your address is: \n#{street_number} #{street_name}\n#{city_name}, #{state_name} #{zip_code}\nYour phone number is #{phone_number} and your email address is #{email_address}.\nIs this correct? ") if correct puts("Great! Let's continue!") else puts("Please come back when you know where you live.") exit 1 end #this section gets the objective of the candidate. objective = prompt("Please enter a short description of your career objective, making sure you use proper rules of capitalization.") correct = boolean_prompt("You said your career objective is, \"#{objective}\" Is this correct?" ) if correct puts("Good, now moving on, let's get a little information about your skills.") else puts("Please come back when you have some goals.") exit 1 end #this section gathers the skillset of the user and puts them into an array. puts("Please enter your technical skills - one per line. When you are complete, please leave a blank line and hit enter.") tech_skills = [] while (answer = gets.chomp) break if answer.empty? tech_skills.push(answer) end puts("Your skills are as follows:\n") tech_skills.each do |skill| puts skill end correct = boolean_prompt("Is this correct?") if correct puts("Great, let's move onto your experience.") else puts("Please come back when you know what you can do with yourself. :)") exit 1 end #This section gathers experience from the user. company1 = Hash.new ["Company Name","Company City","Company State","Start Date","End Date","Position Held","Job Duties"].each do |input| puts("Please enter your #{input}: ") company1 = gets.chomp end correct = boolean_prompt("You worked at " + company1["Company Name"] + " as a " + company1["Position Held"] + " from " + company1["Start Date"] + " until " + company1["End Date"] + " and your job description was as follows: \n" + company1["Job Duties"] + "\n" + company1["Company Name"] + " was located in " + company1["Company City"] + ", " + company1["Company State"] + "Is this correct? ") if correct puts("Great, let's move on!") else puts("Please come back when you have some experience to add to your resume. In other words, GET A JOB! :)") exit 1 end ------------------The above section of code, from the hash section down... gives an error... This is the output... Is this correct? (yes/no) yes Great, let's move onto your experience. Please enter your Company Name: asdf Please enter your Company City: asdf Please enter your Company State: asdf Please enter your Start Date: April 2005 Please enter your End Date: January 2007 Please enter your Position Held: blah Please enter your Job Duties: blah ResumeBuilder.rb:85:in `+': can't convert nil into String (TypeError) from ResumeBuilder.rb:85 /projects/dev/ResumeBuilder $ Line 85 begins with: correct = boolean_prompt("You worked at " + comp... I'm really at a loss here. I thought that each company would fit nicely into a Hash value... I've been banging my head against the wall for a while now on this one. -- Samantha http://www.babygeek.org/ "Beware when the great God lets loose a thinker on this planet. Then all things are at risk." --Ralph Waldo Emerson ------=_Part_54709_23592294.1172718143523--