# You will laugh when you look at it!!

• 02-26-2011
bilgee0629
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
• 02-27-2011
anon
You should post what you have, because this is indeed trivial.
• 02-27-2011
kmdv
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.
• 02-27-2011
bilgee0629
here it is.
Code:

```#include <iostream> using namespace std; int main() {   int a;   while (a==42)   {     cin >> a;          } return 0; }```
• 02-27-2011
bilgee0629
Quote:

Originally Posted by kmdv
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 :D
• 02-27-2011
kmdv
Quote:

Originally Posted by bilgee0629
Please write it for me. I swear i won't post something like this here again :D

No.

I gave you the entire algorithm. You can omit step 2. And before comparing 'a' you should assign something to it.
• 02-27-2011
bilgee0629
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.
• 02-27-2011
kmdv
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.

Quote:

Although i do know the algorithm, i couldn't write the code.
You didn't say this in your first post.
• 02-27-2011
bilgee0629
Sorry for writing my circumstance uncertainly. Thank for reply :)
• 02-27-2011
GReaper
Quote:

Originally Posted by bilgee0629
Please write it for me. I swear i won't post something like this here again :D

Just imagine what would happen if every new guy asked that! ( Many do, but most are discouraged by our steardy attitude! :D )
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! :D
• 02-27-2011
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
• 02-27-2011
kmdv
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...
• 02-28-2011
bilgee0629
Quote:

Originally Posted by Sipher
Just imagine what would happen if every new guy asked that! ( Many do, but most are discouraged by our steardy attitude! :D )
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! :D

it's just a way to attract people, you know :)