79 / 103
Dec 2015
1 month later
8 days later
1 month later
26 days later

My solution doesn't pass your tests. It compiles on my local system and seems to satisfy the requirements. I am using mingw492_32 compiler on my computer.

Question: How do I wrap this in a code block where it picks up my includes and angle brackets accurately?

(pound symbol)include < iostream>
(pound symbol)include < list>
using namespace std;

int main(void) {
int val;
list< int> array;

cout << "Input:" << endl;
while (true) {
    cin >> val;
    if (val > 99 || val < -99)
        continue;
    if (val == 42)
        break;
    array.push_back(val);
}
cout << "\n\nOutput:" << endl;
for (list<int>::iterator iter = array.begin(); iter != array.end(); iter++)
    cout << *iter << endl;
return 0;

}

1 month later

Please keep in mind that this is my first day working with c++ (or any language). Having only a limited knowledge of using the iostream header, this is what I came up with:

#include <iostream>
using namespace std;

int main()
{
	int a;
	cin >> a;
	
	while (a != 42)
	{
		cout << a << endl;
		cin >> a;
	}

	return 0;
}
2 months later
4 months later

It would better to use "using namespace std;" after header file.While loop is used for repeatation that we do not know the limit how times the loop will continue.It is better to use control statements such as" if , if else or switch case" for conditions.

7 months later

Any help? "Wrong answer"

include

include

//void read();
using namespace std;

int main() {


//read();

int number=0;
std::fstream in;
std::fstream out;
in.open("data.txt");
out.open("output.txt");

if (in.good()) {
	in >> number;

	while (number != 42) {
		out << number << endl;
		in >> number;
		
	}
}



return 0;

}

21 days later

This code gets accepted on CodeChef but it's saying "Wrong Answer" on SPOJ. If anyone can figure out what am I doing wrong. Help would be greatly appreciated.
`#include < iostream >
using namespace std;

int main() {
int x;
while(cin>>x ){

	if(x==42)
		break;
	cout<<x<<endl;

}
return 0;

} `

21 days later

Can someone say what is the problem here?
Judge shows wrong answer:

#include<iostream>
using namespace std;

int main (){
	int number;
	freopen("index.txt","r", stdin );
	cin>>number;
	int P[number-1];
	for(int i=0;i<number;i++){
		cin>>P[i];
		if(P[i] == 42)
			break;
			cout<<P[i]<<'\n';
	}
}

hi what is the problem in this code.?
#include
using namespace std ;
int main()
{
int n[5],i;
for (i=0; i<=5;i++){
cin>>n[i];
}
for (i=0; i<=5;i++){
if (n[i]==42)
break;
else{
cout<<n[i]<<endl;
}
}
return 0;

}

6 months later

Why it’s wrong?
#include
using namespace std;

int main()
{
int i,j,k,l,num[1000];
cout<<“Enter how many numbers you want to add:”;
cin>>i;
for(j=0;j<i;j++){
cin>>num[j];
if(num[j]==42){
break;
}
cout<<num[j]<<endl;
}
}

This text doesn’t appear in the sample output given in the problem, so you shouldn’t write it either.

The problem doesn’t say there will be 1000 numbers or or fewer, so it’d be better if you didn’t assume it.

12 months later
#include<iostream>
#include <list>
#include <iterator>
using namespace std;

void outputNumber(list <int> g){
    list <int> :: iterator it;
    for(it = g.begin(); it != g.end(); ++it) {
        if(*it==42){
            break;
        }else{
            cout<<*it<<endl;
        }
    }
}

int main(){
    int myints[] = {1,2,88,42,99};
    std::list<int> testInputs (myints, myints + sizeof(myints) / sizeof(int) );
    std::cout << "The contents of the tested inputs are: ";
  for (std::list<int>::iterator it = testInputs.begin(); it != testInputs.end(); it++)
    std::cout << *it << ' ';

  std::cout << '\n';
    outputNumber(testInputs);
    return 0;

}

my codes have output the correct answers, but the compiler does not accept it


2 months later

The problem in the code lies in the while loop condition , i am not able to end taking the input, help!!
#include
#include<stdlib.h>
using namespace std;
int main()
{
int x[100],n=0,i=0;
while(cin>>n)
{

	x[i]=n;
	i++;
}
for(int j=0;j<=i;j++)
{
	if(x[j]==42) exit(15);
	else
	std::cout<<x[j]<<endl;
}
return 0;

}

1 year later

I did it in a simple way! Hope it becomes of some help :wink:

And cross-question for you :smiley:
How can I manage memory properly in this program???

#include<stdio.h>

int main(){
      int arr[1000],i=0,n=0;
      do{
            scanf("%d",&arr[i]);
            i++;
            n++;
      }while(arr[i-1]!=42);
      for(i=0;i<(n-1);i++){
            printf("%d\n",arr[i]);
      }
      return 0;
}