View Poll Results: Who do you think is the best beginner?

Voters
19. You may not vote on this poll
Page 4 of 22 FirstFirst ... 2345614 ... LastLast
Results 31 to 40 of 217

Thread: [Beginner] Programming Challenge: 2

  1. #31
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Wybiral View Post
    HTML 4.01 Strict
    Too many errors

    Not valid for the contest.

    Remember, a single warning in the compilation phase disqualifies. You had show stopping errors.

  2. #32
    Join Date
    Sep 2006
    Beans
    2,914

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by arsenic23 View Post
    Thanks, the bash help I had been using never explained the need for "(( ))" when comparing ints. In fact it had a chart that said that -lt and < where the same thing. I had tried something like [ $((val < 9)) ] thinking it was something like that and having used $(( stuff )) to do simple math is bash before. heheh
    the advance bash guide is very useful. if you could finish it, it would benefit you alot.

    So is there a terribly good reason to use a while loop in this situation? I really only did it like this because I was interested in seeing if bash would get angry if I had functions call themselves. I put in incorrect input over and over again to see if it would raise a fuss, but it seemed to work alright.
    An infinite loop has the effect of repetition. If input is not valid, you will do it again. recursion has the same effect, however, they have different consequences which i will not elaborate further.
    here's my sketch, you can easily understand after reading the links i gave
    Code:
    while true
    do
     read -p "Enter user name: " username
     username=${username:0:20}  #get 20 characters.
     [ -z "$username" ] && continue
     read -p "Enter age: " age
     [[ "$age" =~ [a-z]+ ]]|| (("$age" <= 0 ))  || (("$age" > 100 ))  && echo "Invalid age" && continue # age 1 onwards?
     read -p "Enter userid: " userid
     ....
     ....
     printf "You entered valid input"
    done
    Last edited by ghostdog74; August 6th, 2008 at 06:54 AM.

  3. #33
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by LaRoza View Post
    Too many errors

    Not valid for the contest.

    Remember, a single warning in the compilation phase disqualifies. You had show stopping errors.
    It passes this: http://validator.w3.org/#validate_by_input

  4. #34
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Wybiral View Post
    It doesn't pass firebug.

  5. #35
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by LaRoza View Post
    It doesn't pass firebug.
    It does for me...

  6. #36
    Join Date
    Apr 2006
    Beans
    571
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Wybiral View Post
    It does for me...
    Me too, incase you started thinking you where crazy.
    Works in firefox 3.0.1 and Opera 9.5 on my box. (64bit)

  7. #37
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Wybiral View Post
    It does for me...
    Firebug finds things in jquery.js to complain about.

  8. #38
    Join Date
    Mar 2008
    Location
    Back to India
    Beans
    278
    Distro
    Ubuntu Gnome 14.04 Trusty Tahr

    Smile Re: [Beginner] Programming Challenge: 2

    Dear Laroza,
    I want to write a shell script for this, But I need some help, regarding shell script commands. Can U pls guide some URL containing good treasure of shell scripting commands.

  9. #39
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by Vishal Agarwal View Post
    Dear Laroza,
    I want to write a shell script for this, But I need some help, regarding shell script commands. Can U pls guide some URL containing good treasure of shell scripting commands.
    The guide posted by ghostdog above, or my wiki.

  10. #40
    Join Date
    Sep 2007
    Location
    New Zealand
    Beans
    17
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: [Beginner] Programming Challenge: 2

    My java version of this
    Code:
    /**
     * Input manipulation challenge
     * 
     * @author Simon McMahon
     * @version 1.0
     */
    
    import java.util.Scanner;
    
    public class InputChallenge
    {
        private static Scanner scan = new Scanner(System.in);
        
        
        
        
        private static String getName() {
            
            String input = "";
            String name = "";
            
    		boolean nameLegal = false;
    		
    		System.out.println("Please enter your username. No leading spaces please. type exit to quit");
    		while(!nameLegal) {
    		      try {
    		          input = scan.nextLine();
    		    
    		          if(input.equals("") || input.charAt(0) == ' ') {
    		               System.out.println("Invalid username. Please enter again. type exit to quit");
    		          } else {
    		              name = input;
    		              nameLegal = true;
    		          }
    					
    		      } catch(Exception e) {
    		          System.out.println("Invalid username. Please enter again. type exit to quit");
    		      }
    		  }
    		return name;
        }
        
        private static int getAge() {
    		
    		boolean ageLegal = false;
    		int age = 0;
    		String aInput = "";
    		System.out.println("Please enter your age. type exit to quit");
    		while(!ageLegal) {
    		   try {
    		          aInput = scan.nextLine();
    			
    		          if (aInput.toLowerCase().equals("exit")) {
    		                  return -1;
    		          }
    		    
    		   
    		          if(aInput.equals("") || Integer.parseInt(aInput) < 1) {
    		              System.out.println("Invalid age. Please enter again. type exit to quit");
    		          } else {
    		              age = Integer.parseInt(aInput);
    		              ageLegal = true;
    		    
    		          }    
    		    } catch (Exception n) {
    		          System.out.println("Invalid age. Please enter again. type exit to quit");
    		    }
    					
    		}
    		return age;
        }
        
        
        private static int getID() {
    		
    		boolean IDLegal = false;
    		int ID = 0;
    		String dInput = "";
    		System.out.println("Please enter your ID number. type exit to quit");
    		while(!IDLegal) {
    		    try {
    		          dInput = scan.nextLine();
    			
    		          if (dInput.toLowerCase().equals("exit")) {
    		              return -1;
    		          }
    		        
    		          if(dInput.equals("") || Integer.parseInt(dInput) < 1) {
    		              System.out.println("Invalid user ID. Please enter again. type exit to quit");
    		          } else {
    		              ID = Integer.parseInt(dInput);
    		              IDLegal = true;
    		    
    		          }    
    		    } catch (Exception n) {
    		          System.out.println("Invalid user ID. Please enter again. type exit to quit");
    		    }
    					
    		}
    		return ID;
        }
    
        
        public static void main(String[] args) {
            String name = getName();
            if(!name.toLowerCase().equals("exit")) {
                int age = getAge();
                if (age != -1) {
                    int ID = getID();
                    if (ID != -1) {
                        System.out.print("You are " + name + ", aged " + age);
                        System.out.print(". Next year you will be " + (age + 1));
                        System.out.println(". Your user ID is " + ID + " and the next user will be " + (ID + 1) + ".");
                    }
                }
            }
            System.out.println("Thank you for using this program.");
                
        }
    }

Page 4 of 22 FirstFirst ... 2345614 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •