#include<iostream> #include<fstream> #include<sstream> #include<cmath> #include<cstdlib> #include<string> #include<list> #include<vector> #include<algorithm> #include<stdexcept> using namespace std; inline void keep_window_open() {char ch; cin>>ch;} void get_instructions() { cout<<"\n"; cout<<"1)";cout<<"\n"; cout<<"you enter a number to let me play";cout<<"\n"; cout<<"(either 0, 1 or 2)";cout<<"\n"; cout<<"\n"; cout<<"1)";cout<<"\n"; cout<<"you'll play \"rock\" \"paper\" or \"sicssors\"";cout<<"\n"; cout<<"if I play same as you we draw";cout<<"\n"; cout<<"rock beat scissors but paper beat rock";cout<<"\n"; cout<<"scissors beat paper"; cout<<"\n"; } void get_started() { cout<<"\n"; cout<<"o o o oooo o ooo oo o o oooo";cout<<"\n"; cout<<" o o o o o o o o o o o o o o ";cout<<"\n"; cout<<" o o o o oooo o o o o o o o oooo";cout<<"\n"; cout<<" oo oo o o o o o o o o ";cout<<"\n"; cout<<" o o oooo ooo ooo oo o o oooo";cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<<"MY version of \"rock paper scissors\"";cout<<"\n"; cout<<"\n"; cout<<"know how to play? "; string start; cin>>start; while (start!="no" and start!="yes") { cin.clear(); cin.ignore(80,'\n'); cout<<"answer \"yes\" or \"no\" "; cin>>start; } if (start=="yes") { cout<<"..here you go!"; cout<<"\n"; } else if (start=="no") { get_instructions(); } } double get_double() { double maybe_double=0; while (!(cin>>maybe_double)) { cin.clear(); cin.ignore(80,'\n'); cout<<"..double please "; cout<<"\n"; cin>>maybe_double; } return maybe_double; } int get_int() { double num = get_double(); while (num != static_cast<int>(num)) { cout <<"..integers please "; num = get_double(); } return static_cast<int>(num); } int get_inrange(int low, int high) { int num = get_int(); while (num<low or num>high) { cout<<"integer must be from "; cout<<low<< " to " << high; cout<<". Try Again: "; num = get_int(); } return num; } int me_play() { int value1=0; string value; cout<<"enter your play "; cin>>value; while (value!="rock" and value!="paper" and value!="scissors") { cin.clear(); cin.ignore(80,'\n'); cout<<"..rock, paper or scissors please "; cin>>value; } if (value=="rock") { value1=0; } else if (value=="paper") { value1=1; } else if (value=="scissors") { value1=2; } else {}; return value1; } int computer_play(int i) { int value2=0; int cmptr=0; vector<int>first_sequence; vector<int>second_sequence; vector<int>third_sequence; cout<<"seed me with a number please: "; cin>>cmptr; while (cmptr!=0 and cmptr!=1 and cmptr!=2) { cin.clear(); cin.ignore(80,'\n'); cout<<"..0, 1 or 2 please "; cin>>cmptr; } if (cmptr==0) { first_sequence.push_back(1); first_sequence.push_back(0); first_sequence.push_back(1); first_sequence.push_back(0); first_sequence.push_back(2); first_sequence.push_back(0); first_sequence.push_back(1); first_sequence.push_back(2); first_sequence.push_back(2); first_sequence.push_back(2); value2=first_sequence[i]; } if (cmptr==1) { second_sequence.push_back(1); second_sequence.push_back(2); second_sequence.push_back(2); second_sequence.push_back(0); second_sequence.push_back(1); second_sequence.push_back(0); second_sequence.push_back(1); second_sequence.push_back(0); second_sequence.push_back(0); second_sequence.push_back(2); value2=second_sequence[i]; } if (cmptr==2) { third_sequence.push_back(2); third_sequence.push_back(0); third_sequence.push_back(0); third_sequence.push_back(0); third_sequence.push_back(0); third_sequence.push_back(0); third_sequence.push_back(1); third_sequence.push_back(0); third_sequence.push_back(2); third_sequence.push_back(2); value2=third_sequence[i]; } return value2; } int main() { int i=0; int counter_me=0; int counter_cmptr=0; string answer; string start; get_started(); cout<<"\n"; cout<<"want to play? "; cin>>answer; while (answer!="yes" and answer!="no") { cin.clear(); cin.ignore(80,'\n'); cout<<"answer \"yes\" or \"no\" "; cin>>answer; } while (answer=="yes") { cout<<"\n"; int cmptr = computer_play(i); int me = me_play(); if (cmptr==0) { cout<<"I say rock!"; cout<<"\n"; if (me==0) cout<<"nobody won"; else if (me==1) {cout<<"you won"; counter_me++;} else if (me==2) {cout<<"I won"; counter_cmptr++;} else cout<<"some mess happened"; } else if (cmptr==1) { cout<<"I say paper!"; cout<<"\n"; if (me==0) {cout<<"I won"; counter_cmptr++;} else if (me==1) cout<<"nobody won"; else if (me==2) {cout<<"you won"; counter_me++;} else cout<<"some mess happened";; } else if (cmptr==2) { cout<<"I say scissors!"; cout<<"\n"; if (me==0) {cout<<"you won"; counter_me++;} else if (me==1) {cout<<"I won"; counter_cmptr++;} else if (me==2) cout<<"nobody won"; else cout<<"some mess happened";; } else cout<<"ERROR MESSAGE: please close game and restart!"; cout<<"\n"; cout<<"my points: "<<counter_cmptr; cout<<"\n"; cout<<"your points: "<<counter_me; cout<<"\n"; if (counter_cmptr>counter_me) { cout<<"I am winning now"; } else if (counter_cmptr<counter_me) { cout<<"you are winning now"; } else { cout<<"nobody is currently winning"; } cout<<"\n"; cout<<"do you want to play again? "; cin>>answer; i++; while (answer!="yes" and answer!="no") { cin.clear(); cin.ignore(80,'\n'); cout<<"answer \"yes\" or \"no\" "; cin>>answer; } } cout<<"\n"; cout<<"It would have been fun playing more with you..";cout<<"\n"; cout<<"all right then.. I will miss you "; keep_window_open(); return 0; } |
|
|
http://msdn.microsoft.com/en-us/library/3akey979%28v=vs.80%29.aspx |
The xor operator is the text equivalent of ^. There are two ways to access the xor operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option. |
http://en.wikipedia.org/wiki/Iso646.h |
These identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file. For consistency, the C++98 standard provides the header <ciso646>. However the latter file has no effect, being empty.[1] Notwithstanding some compilers, such as Microsoft Visual C++, do require the header to be included in order to use these identifiers. |
These identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file. |
int a(1);
int a = 1;
I just copied an pasted just to make sure :D |
How can you clear the screen? |
system( "cls" );
, which simply clears the screen. Have a look at this: http://cplusplus.com/forum/beginner/1988/ to see why it is controversial. Another way is going through all console coordinates and setting them to " " (using SetConsoleCursorPosition() or something, http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx ).How can I send it to a frend of mine in a different country? Does he have to compile it? can I send the application directly? |