I write this code and got pass in test.
The common mistake every one do in the beginnign is they actually put some helping text on cout to tell others what to do which is not needed.
#include <iostream>
using namespace std;
int main(){
int x=0;
cin >> x;
while(x != 42){
if (x <=99){
cout << x <<endl;
cin >> x;
}else {
cin >> x;
}
}
}
my code is given below...my problem is just about the termination of input when i enter blank or simply press the return key...i appreciate any help..thanks alot!!
include
include
include
using namespace std;
main()
{
int input;
vectorv;
while(scanf ( "%d", &input ) == 1 )
{
//cin>>input;
if(!input)
break;
else
v.push_back(input);
}
vector<int>::iterator i;
for(i=v.begin();i<v.end();i++)
{
if(*i!=42)
cout<<*i<<endl;
else break;
}
}
i'm having the same "wrong answer". I don't know what's wrong! i get the right output! D:
#include <iostream>
using namespace std;
int main() {
int n, n2, n3, n4, n5;
cin>>n;
cin>>n2;
cin>>n3;
cin>>n4;
switch(n4==42)
{
break;
case 1:
cin>>n5;
cout<<n<<endl;
cout<<n2<<endl;
cout<<n3<<endl;
break;
}
}
Here's a good description / explanation on how to solve this problem Life universe and everything problem in C++, C, and Java:
include
int main()
{ int n;
while(1)
{ cin>>n;
if(n==42)
break;
cout<<"\n"<}
return;
}
this is the edited code but this is also not working.it shows a compilation error.Could someone please give a sample code in c++ which will be accepted by spoj because when i compile it in my compiler then it shows no error.
#include<iostream>
CODE: SELECT ALL
using namespace std;
int main()
{ int n;
while(1)
{ cin>>n;
if(n==42)
break;
cout<<"\n"<<n<<"\n";
}
return 0;
}
these are the errors it is showing after the correction
prog.cpp:2: error: function definition does not declare parameters
prog.cpp: In function 'int main()':
prog.cpp:7: error: 'cin' was not declared in this scope
prog.cpp:10: error: 'cout' was not declared in this scope
include
using namespace std;
int main()
{
int i,n,a[20];
cout<<"How Many Numbers Do u want to use as input :- ";
cin>>n;cout< for( i=0;i {
cin>>a[i];
}
cout<<"\nHere your output:- ";
for( i=0;i {
if(a[i]!=42)
cout<<" " < else if(a[i]==42)
break;
}
}
i hv written the prgrm using array 1st u hv to give all the no that u want to use as input & then it gives u the output as mentioned in the qstn, so where am i wrng??