Store the current value in a second variable?
Store the current value in a second variable?
sorry this is correct:
could someone solve my prob?Code:#include <iostream> #include <stdlib.h> using namespace std; void messageFunction(); void Header(); int main() { int a=0; int num; Titlos(); cout<<endl; messageFunction(); cout<<"Choose an option:"<<endl; cin>>num; while (num==1&&a<5) { a++; cout<<"You bought seat "<<a<<endl; cin>>a; break; } return main(); system("PAUSE"); return 0; } void messageFunction(void) { cout<<"Type 1 for First class"<<endl; } void Header() { cout<<"********Exercise 3 Solution********"<<endl; }
Ready..Steady..Doom!!!
>return main();
Recursive calls to main aren't legal C++. Use a loop instead.
My best code is written with the delete key.
ok, i have tryied a lot of patterns but with no result..
Ready..Steady..Doom!!!
>i have tryied a lot of patterns but with no result..
It would help if you explained exactly what input you want to give, and what output you expect. There are many times when just looking at the code doesn't help us to understand your intentions at all. Is this what you want?
If not, you'll need to describe what you want, in painful detail.Code:#include <iostream> #include <cstdlib> using namespace std; void messageFunction(); void Header(); int main() { int a=0; int num; Header(); do { cout<<endl; messageFunction(); cout<<"Choose an option:"<<endl; cin>>num; if (num == 1) { a++; cout<<"You bought seat "<< a <<endl; } else { break; } } while (a < 5); system("PAUSE"); return 0; } void messageFunction(void) { cout<<"Type 1 for First class"<<endl; } void Header() { cout<<"********Exercise 3 Solution********"<<endl; }
My best code is written with the delete key.
No my code worked as intended in my compiler o-oOriginally Posted by Prelude
Code:#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int in; int array[0]; array[0]=0; cout<<"Please enter a number"; cin>>in; array[0]=in; cout<<"Array value is now:"<<array[0]; system("PAUSE"); return 0; }
To code is divine
Which means your compiler is not conforming to the standard and will be exhibiting undefined behavior. Don't even get Prelude started on that.No my code worked as intended in my compiler o-o
>No my code worked as intended in my compiler o-o
My compiler can beat up your compiler.
My best code is written with the delete key.
Told you so...My compiler can beat up your compiler.
Dev-CPP + $120 > Visual C++Originally Posted by Prelude
edit: not really, but I do like my money in my pocket for now
To code is divine
>Dev-CPP + $120 > Visual C++
Who said I was talking about Visual C++? I was making a "My dad can beat up your dad" joke, but that doesn't change the fact that your excuse for broken code was that it happened to work on your implementation. That's a horrible excuse, but I'll let it slide because Dev-C++ really does compile it without warnings. Though I'll continue to wonder how you thought an array of size 0 should work.
My best code is written with the delete key.
Or why you'd want it to...Though I'll continue to wonder how you thought an array of size 0 should work.