View Poll Results: Who was the best beginner?

Voters
41. You may not vote on this poll
Page 14 of 27 FirstFirst ... 4121314151624 ... LastLast
Results 131 to 140 of 268

Thread: [Beginner] Programming Challenge: 1

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

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by jimi_hendrix View Post
    if you know how to stop a console app in C++ from closing like the one in my post, please tell me, because i need to do a line break to keep it from closing and that feels like cheating
    The program stays open while it is running. If you are running it from a terminal, that is good. If you are double clicking it, it is bad. The solution is don't double click!

    Using such getchar() things and pausing it just leads to wasted energy when it is run from the terminal, which it should be.

  2. #132
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 1

    i really wish vista had a terminal

  3. #133
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 1

    It has command prompt,terminal is only under Unix oses,you should do your programming under Linux

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

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by jimi_hendrix View Post
    i really wish vista had a terminal
    Press start menu, type "cmd" press enter.

  5. #135
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 1

    i know but its not nearly as good ive never have had to use it

  6. #136
    Join Date
    Aug 2005
    Location
    The Local Group
    Beans
    631

    Re: [Beginner] Programming Challenge: 1

    Here's my updated code:
    Code:
    import Char(toUpper)
    
    main = putStrLn (e 99)
    
    e :: Int -> String
    e x = ((\(c : cs) -> (toUpper c : cs))(d x)) ++ ", " 
          ++ (c x) ++ ".\n" 
          ++ if x == 0
             then "Go to the store and buy some more, " ++ (d 99) ++ "."
             else "Take one down and pass it around, " ++ (d (x-1)) ++ ".\n\n"
                      ++ (e (x-1))
    
    d :: Int -> String
    d x = (c x) ++ " on the wall"
    
    c :: Int -> String
    c x = (if x == 0 then "no more" else show x)
          ++ " bottle" ++
          (if x == 1 then "" else "s")
          ++ " of beer"
    I don't promise that it won't be updated again, since I'm still learning the ins and outs of Haskell.

    I chose this design in order to minimize the amount of repeated text in the source code. Every major word or phrase (e. g., "bottle(s)", "of beer", etc.) only appears once.

  7. #137
    Join Date
    May 2008
    Location
    Atlanta, GA, USA
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [Beginner] Programming Challenge: 1

    Code:
    #include <iostream>
    using namespace std;
    
    void printBottles(int);
    
    int main(int argc, char** argv)
    {
            int beer = 99;
    
            printBottles(beer);
            return 0;
    
    }
    
    void printBottles(int beer)
    {
            switch(beer)
            {
          case 0:
              {
               cout <<  "No bottles of beer on the wall, no bottles of beer.\nGo to the store and buy some more. 99 bottles of beer on the wall.\n" << endl;
           return;
              }
    
              case 1:
              {
              cout << beer << " bottle of beer on the wall, " << beer << " bottle of beer.\nTake one down and pass it around, no more bottles of beer on the wall.\n" << endl;
              printBottles(beer - 1);
              }
              break;
    
              case 2:
              {
             cout << beer << " bottles of beer on the wall, " << beer << " bottles of beer.\nTake one down and pass it around, " 
                          << beer - 1 << " bottle of beer on the wall.\n" << endl;
             printBottles(beer - 1);
              }
              break;
              default:
              {
                    cout << beer << " bottles of beer on the wall, " << beer << " bottles of beer.\nTake one down and pass it around, "
                             << beer - 1 << " bottles of beer on the wall.\n" << endl;
                    printBottles(beer - 1);  
              }
              break;
            };
    }
    First post. It's been a long time since I've done any C++.

  8. #138
    Join Date
    Apr 2007
    Location
    Toronto
    Beans
    104
    Distro
    Ubuntu 13.04 Raring Ringtail

    Question Re: [Beginner] Programming Challenge: 1

    Hello,

    Here is my submission in Python. I am not a new programmer, but I am a fairly new Python programmer. I thought I would keep this task fairly basic by letting the
    Code:
    range()
    function take care of most of the work for me.

    PHP Code:
    #!/usr/bin/env python
    #
    #       99_Bottles.py
    #       
    #       Copyright 2008 Aaron <aaron@aaron-laptop>
    #       
    #       This program is free software; you can redistribute it and/or modify
    #       it under the terms of the GNU General Public License as published by
    #       the Free Software Foundation; either version 2 of the License, or
    #       (at your option) any later version.
    #       
    #       This program is distributed in the hope that it will be useful,
    #       but WITHOUT ANY WARRANTY; without even the implied warranty of
    #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #       GNU General Public License for more details.
    #       

    def drink_me(n):
        for 
    i in range(n,0,-1):
            if 
    1:
                print 
    i"bottles of beer on the wall"i" bottles of beer.\nTake one down, pass it around", (i-1), "bottles of beer on the wall.\n"
            
    else: 
                print 
    "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more",n,"bottles of beer on the wall.\n"
        
    return 0
    def main
    ():
        
    drink_me(99)
        return 
    0

    if __name__ == '__main__'main() 
    Last edited by AaronMT; August 3rd, 2008 at 10:23 PM.

  9. #139
    Join Date
    Aug 2007
    Location
    Can.
    Beans
    82
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: [Beginner] Programming Challenge: 1

    can you do this again this is so cool for me to read all your ideas . i am self taught so seeing your answers are interseting . there really are more than one way to do this .

  10. #140
    Join Date
    Jan 2008
    Beans
    15
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [Beginner] Programming Challenge: 1

    I decided to go with this semi-recursive method, since the iterative method has been done before. I have some repeated code in there, which bothers me, but here it is anyways. Maybe I'll try another language next.

    PHP Code:
    #!usr/bin/perl
    package Beer;
    use 
    strict;

    # Can start with any number of beers, default is 99.
    our $numBeers = ($ARGV[0] && $ARGV[0] =~ m|\d+|) ? $ARGV[0] : 99;

    &
    sing($numBeers);
    &
    getMore($numBeers);

    # Print the first line of each verse.
    sub sing {
        
    my $Beer my $beer shift#Capitalized and uncapitalized version
        
    my $s = ($beer == 1) ? "" "s";
        
    $Beer =~ s|n|N|;
        print 
    "$Beer bottle$s of beer on the wall, $beer bottle$s of beer.\n";
        &
    takeOne(--$beer) if ($beer =~ m|\d+|);    
    }

    # Print the second line of each verse (except the last).
    sub takeOne {
        
    my $beer shift;
        
    my $s = ($beer == 1) ? "" "s";
        
    $beer = ($beer == 0) ? "no more" $beer;
        print 
    "Take one down and pass it around, $beer bottle$s of beer on the wall.\n\n";
        &
    sing($beer);
    }

    # The last line.
    sub getMore {
        
    my $s = ((my $beer shift) == 1) ? "" "s";
        print 
    "Go to the store and buy some more, $beer bottle$s of beer on the wall.\n";


Page 14 of 27 FirstFirst ... 4121314151624 ... 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
  •