# Thread: You will laugh when you look at it!!

1. ## 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. You should post what you have, because this is indeed trivial.

3. 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.

4. ## here it is.

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

}```

5. 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

6. Originally Posted by bilgee0629
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.

7. 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. 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.

9. Sorry for writing my circumstance uncertainly. Thank for reply

10. Originally Posted by bilgee0629
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!

11. 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. 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...

13. 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! )
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