[edit] Previous post deleted.
Having re-read the question, I have a different take on what it means.
It appears that what is being asked is, from the input of: 1, 2, 88, 42, 99 - output must be each digit up until when 42 is typed, then no output from anything entered.
I now have a program that does that:
#include <iostream>
int main()
{
using std::cin;
using std::cout;
using std::endl;
int inputDigit;
for (int i = 0; i <= 10; i++)
{
cin >> inputDigit;
if (inputDigit != 42)
{
cout << endl << inputDigit;
}
else
{
return 0;
}
}
return 0;
}
It's messy, but it works. However, on submission I got "wrong answer". Blah!
-Oscarian
[edit] edited to save multiple posts.
Guys, even if any of those hideous solutions work, which is a lot to say for the very first and easiest problem ever to exist, they will land you a time of 0.01.
The I/Ostream library is SLOW as hell - depending on what you read/write to the stream, they are at LEAST 10 times slower than the standart reading/writing functions in stdio. Use stdio.h.
About the problem - try the following:
#include <stdio.h>
int main() {
int x; //= 0 init
scanf("%d", &x);
while(x != 42) {
printf("%d\n", x);
scanf("%d", &x);
}
return 0;
}
There are still better approaches to the problem.
[quote="noix"]
#include <iostream>
int main(void) {
char c, d=10;
while(std::cin.get(c) && (c!='2' || d!='4') && std::cout.put(d))
d=c;
}
[/quote]
This TEST solution is wrong, isn'it?
In case of input 8, 99, 4, 2, 10, 42, 3 it will output 8, 99.
I see that it's enough that it works for the test case, but as example answer it is not the best...
Ok i've manged to find a solution but when i submit it i got wrong answer even though it's doing what it's supposed to do
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int x;
do
{
scanf ("%d", &x);
printf (" %d \n", x);
}
while (x != 42);
return 0;
}
so what i'm doing wrong?