You will laugh when you look at it!!

This is a discussion on You will laugh when you look at it!! within the C++ Programming forums, part of the General Programming Boards category; I'm new in c++ . So i'm struggling to solve this question, please help me!!! ******* Your program is to ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6

    Question You will laugh when you look at it!!

    I'm new in c++ . So i'm struggling to solve this question, please help me!!!

    *******
    Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.


    Example
    Input:
    1
    2
    88
    42
    99

    Output:
    1
    2
    88

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You should post what you have, because this is indeed trivial.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    Well, I didn't laugh much but I will give a clue:

    1. Read number and store it in a local variable.
    2. Test if the operation failed. If it did it means that there are no more numbers and you need to terminate the program.
    3. Test if the local variable equals 42, if it does, terminate the program.
    4. Otherwise, print this number (the local variable) and get back to step 1.
    I never put signature, but I decided to make an exception.

  4. #4
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6

    Talking here it is.

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
       int a;
       while (a==42)
       {
         cin >> a;	 
       }
    return 0;
    
    }

  5. #5
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6
    Quote Originally Posted by kmdv View Post
    Well, I didn't laugh much but I will give a clue:

    1. Read number and store it in a local variable.
    2. Test if the operation failed. If it did it means that there are no more numbers and you need to terminate the program.
    3. Test if the local variable equals 42, if it does, terminate the program.
    4. Otherwise, print this number (the local variable) and get back to step 1.
    Please write it for me. I swear i won't post something like this here again

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    Quote Originally Posted by bilgee0629 View Post
    Please write it for me. I swear i won't post something like this here again
    No.

    I gave you the entire algorithm. You can omit step 2. And before comparing 'a' you should assign something to it.
    I never put signature, but I decided to make an exception.

  7. #7
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6
    The reason i wrote this thread is code of this problem. Although i do know the algorithm, i couldn't write the code. I guess i could get a glue from your code.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    You need to read number before the loop too. The loop condition is also bad.
    "while (a == 42)" means "if a equals 42, enter the loop block, otherwise do not" and this is not what you wanted.

    Although i do know the algorithm, i couldn't write the code.
    You didn't say this in your first post.
    I never put signature, but I decided to make an exception.

  9. #9
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6
    Sorry for writing my circumstance uncertainly. Thank for reply

  10. #10
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Quote Originally Posted by bilgee0629 View Post
    Please write it for me. I swear i won't post something like this here again
    Just imagine what would happen if every new guy asked that! ( Many do, but most are discouraged by our steardy attitude! )
    Anyway, good luck in what you're trying to do. Don't give up! Programming needs patience! ( Someone who's not so patient tells you this. )

    EDIT: I can't see the fun either! Do you know why a joke is called cold? Because your lips freeze!
    Last edited by GReaper; 02-27-2011 at 05:12 AM.
    Devoted my life to programming...

  11. #11
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Isn't this the very first problem in one of those online judge competition things? If you get someone to answer the easiest one for you, what chance do you think you stand with every other problem?

    EDIT: Oh yeah, I guess it is

  12. #12
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    671
    Yea, the problem (with input/output format) looked for a programming contest at first sight, but when I realized the difficulty I didn't think about any contest...
    I never put signature, but I decided to make an exception.

  13. #13
    Registered User
    Join Date
    Feb 2011
    Location
    Mongolia
    Posts
    6
    Quote Originally Posted by Sipher View Post
    Just imagine what would happen if every new guy asked that! ( Many do, but most are discouraged by our steardy attitude! )
    Anyway, good luck in what you're trying to do. Don't give up! Programming needs patience! ( Someone who's not so patient tells you this. )

    EDIT: I can't see the fun either! Do you know why a joke is called cold? Because your lips freeze!
    it's just a way to attract people, you know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laugh at my work day
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 06-14-2006, 12:13 PM
  2. Networking in x86 Assembly (try not to laugh at me)
    By sean in forum Networking/Device Communication
    Replies: 6
    Last Post: 12-23-2004, 03:54 AM
  3. feel free to laugh at my code!
    By JimJamJovi in forum C Programming
    Replies: 4
    Last Post: 01-11-2002, 03:40 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21