Loading ...
Sorry, an error occurred while loading the content.
 

Using Loop, if/then, and count program.

Expand Messages
  • tinantaz2
    Write a program that asks the user for two inputs, their first name and last name. Write the first name and last name to a text file, on the same line,
    Message 1 of 2 , May 1, 2009
      Write a program that asks the user for two inputs, their first name and last name. Write the first name and last name to a text file, on the same line, separated by a comma. The end-user will continue to enter first and last names until they enter an "x" for the first name. After the "x" is entered, close the file, then open the file again and count the number of names (lines) in the file, which should be displayed as follows:
      I have ____ name(s) in my file…Give me 50 points!


      NOTE: Do not count each name as it is entered and give me that as the result. You need to open the file and read each line in and keep track of that count.

      start
      open "C:\temp directory\names.txt"; for input as #1
      print #1, "firstName$;lastName$";
      while eof (#1)
      get firstName$, lastName$-------not sure if this is correct----
      if firstName$ <> "x" then close #1
      !!!!here's where I get confused!!!!!
      if not x then get lastName$, print to file, get firstName$
      open "C:temp directory\names.txt"' for input as #2
      input nameCount =0
      eof?
      ???if no eof, input from file, increment nameCount???loop
      if yes eof then close txt file
      print "I have ? name(s) in my file, Give me 50 points!"
      end

      ~Tina
    • Marc Rossi
      Tina I think this will work but again I used my junk1 dir.  Don t forget to use the dir on your computer. Marc open c: junk1 names.txt for output as #1
      Message 2 of 2 , May 2, 2009
        Tina I think this will work but again I used my junk1 dir.  Don't forget to use the dir on your computer.
        Marc
        open "c:\junk1\names.txt" for output as #1
        while first$ <> lower$("x")
        prompt "Enter first name";first$
        prompt "Enter last name";last$
        print #1, first$ ;chr$(44);last$
        wend
        close #1
        notice "Opening file again"
        open "c:\junk1\names.txt" for input as #1
        while not (eof(#1))
         input #1, first$
         input #1, last$
         a = instr(first$, "x")
         if a > 0 then goto [done]
         count = count + 1
        wend
        [done]
        close #1
        print "I have ";count ;" names in my file.  Give me 50 points"


        --- On Fri, 5/1/09, tinantaz2 <tina2260@...> wrote:

        From: tinantaz2 <tina2260@...>
        Subject: [libertybasic] Using Loop, if/then, and count program.
        To: libertybasic@yahoogroups.com
        Date: Friday, May 1, 2009, 2:00 PM








        Write a program that asks the user for two inputs, their first name and last name. Write the first name and last name to a text file, on the same line, separated by a comma. The end-user will continue to enter first and last names until they enter an "x" for the first name. After the "x" is entered, close the file, then open the file again and count the number of names (lines) in the file, which should be displayed as follows:
        I have ____ name(s) in my file…Give me 50 points!

        NOTE: Do not count each name as it is entered and give me that as the result. You need to open the file and read each line in and keep track of that count.

        start
        open "C:\temp directory\names. txt"; for input as #1
        print #1, "firstName$; lastName$ ";
        while eof (#1)
        get firstName$, lastName$--- ----not sure if this is correct----
        if firstName$ <> "x" then close #1
        !!!!here's where I get confused!!!! !
        if not x then get lastName$, print to file, get firstName$
        open "C:temp directory\names. txt"' for input as #2
        input nameCount =0
        eof?
        ???if no eof, input from file, increment nameCount??? loop
        if yes eof then close txt file
        print "I have ? name(s) in my file, Give me 50 points!"
        end

        ~Tina



















        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.