1 / 6
Dec 2023

#include
using namespace std;

int main() {
int n[10];
int count=0;
int i=0;

cout<<“Input :\n”;
for(i=0;i<10;i++)
{

cin>>n[i];
if(n[i] == 42)
{
		cin>>n[i];
		count=i;
i=12;
}

}
cout<<“Output :”<<endl;
for(i=0;i<count;i++)
{
if(n[i]==42)
{
break;
}
else
{
cout<<n[i]<<endl;
}
}

return 0;

}

i do not know why on submission he says its wrong
why iostream is not shown, while posting its here when i post it

You should not be printing the lines containing “Input:” or “Output:”.
When n[i]==42, why do you try to input another value?
Your int n[10] array is unlikely to be large enough; consider not using an array at all.

i also input one number because the example is like
Input:
1
2
88
42
99

Output:
1
2
88

here also input 99 after 42

The instructions say “Stop processing input after reading in the number 42.”

#include
using namespace std;

int main() {
int n[10];
int count=0;
int i=0;

cout<<“Input :\n”;
for(i=0;i<10;i++)
{

cin>>n[i];
if(n[i] == 42)
{
count=i;
i=12;
}
}
cout<<“Output :”<<endl;
for(i=0;i<count;i++)
{
if(n[i]==42)
{
break;
}
else
{
cout<<n[i]<<endl;
}
}

return 0;
}

is this okay ?

You are still printing the lines containing “Input:” & “Output:”.
You are still using an array that is unlikely to be large enough.
Why do you think you need to read the values into an array?