Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
using namespace std; class StateGame { private: string state; string capital; string symbol; string pop; string size; string zone; string nick; int score; string bor; ofstream myfile; string s[51][8]; public: StateGame(); void readLine(); string getState(int); string getSymbol(int); string getCapital(int); string getPop(int); string getSize(int); int getScore(); string getNick(int); string getZone(int); string getborState(int); void updateScore(); int check(int); int check1(int,int); string removeT(string); }; StateGame :: StateGame() { score=100; string State1; string Symbol1; string Capital1; string Pop1; string Size1; string Zone1; string Nickname1; string BorderingStates1; int i=0; string line; ifstream myfile ("input.txt"); if (myfile.is_open()) { for (int lineno = 0; getline (myfile,line); lineno++) { int j=0; State1 = line.substr(0,15); Symbol1 = line.substr(15,7); Capital1 = line.substr(23,15); Pop1 = line.substr(38,5); Size1 = line.substr(42,7); Zone1 = line.substr(49,9); Nickname1 = line.substr(58,25); BorderingStates1 = line.substr(83,40); s[i][j] = State1; j++; s[i][j] = Symbol1; j++; s[i][j] = Capital1; j++; s[i][j] = Pop1; j++; s[i][j] = Size1; j++; s[i][j] = Zone1; j++; s[i][j] = Nickname1; j++; s[i][j] = BorderingStates1; j++; i++; } myfile.close(); } } string StateGame :: removeT(string n) { int t=0,i=0; for(i=0;n[i]!='\0';i++) { if(n[i]==' ' && n[i+1]==' ' && n[i+2]==' ') { t=i; break; } } return n.substr(0,t); } string StateGame :: getState(int num2) { state=s[num2][0]; return state; } string StateGame :: getCapital(int num2) { capital=s[num2][2]; return capital; } string StateGame :: getSymbol(int num2) { symbol=s[num2][1]; return symbol; } string StateGame :: getZone(int num2) { zone=s[num2][5]; return zone; } string StateGame :: getborState(int num2) { bor=s[num2][7]; return bor; } string StateGame :: getNick(int num2) { nick=s[num2][6]; return nick; } string StateGame :: getSize(int num2) { size=s[num2][4]; return size; } string StateGame :: getPop(int num2) { pop=s[num2][3]; return pop; } int StateGame :: getScore() { return score; } void StateGame :: updateScore() { score=score-5; } int StateGame :: check(int num2) { char fs,ls,lc,fc; int cnt=0; int i=1,j=0,g=0; string guess; string st,ca,sy; st=removeT(getState(num2)); sy=removeT(getSymbol(num2)); ca=removeT(getCapital(num2)); vector<int> ar(9); for(int i=0;i<9;i++) { ar[i]=i+1; } random_shuffle(ar.begin(),ar.end()); fs=st.at(0); fc=ca.at(0); ls=st.at(st.length()-1); lc=ca.at(ca.length()-1); do { cout<<"Clue#"<<i; switch(ar[j++]) { case 1: cout<<"the first letter of the state is "<<fs<<"\n"; break; case 2: cout<<"the last letter of the state is "<<ls<<"\n"; break; case 3: cout<<"the first letter of the capital is "<<fc<<"\n"; break; case 4: cout<<"the last letter of the capital is "<<lc<<"\n"; break; case 5: cout<<"The state's rank in population, where 1 is the largest, is "<<getPop(num2)<<"\n"; break; case 6: cout<<"The state's rank in size (or area), where 1 is the largest, is "<<getSize(num2)<<"\n"; break; case 7: cout<<"The state is in the following time zone(s) "<<getZone(num2)<<"\n"; break; case 8: cout<<"The state's nickname is "<<getNick(num2)<<"\n"; break; case 9: cout<<"The state is bordered by the following states: "<<getborState(num2)<<"\n"; break; } cout<<"Current Score "<<getScore()<<"\n"; cout<<"Would you like to guess the state (1) or do you want another clue (2)? "<<"\n"; cin>>g; if(g==2) updateScore(); else if(g==1) { cout<<"Enter your guess name or symbol"<<"\n"; cin>>guess; if((st.compare(guess)==0) || (sy.compare(guess)==0)) { cnt=1; cout<<"Correct! Congratulations! Your final score "<<getScore()<<"\n"; } else { updateScore(); cout<<"Incorrect. Current Score: "<<getScore()<<"\n"; } } i++; if(i>9) j=0; }while(cnt==0 && score!=0); if(cnt==1) { myfile.open ("output.txt",ios :: app); myfile << getState(num2)<<"\t"<<getScore()<<"\n"; myfile.close(); } return getScore(); } int StateGame :: check1(int num2 ,int num1) { string n,n2,name; int score1=100; int score2=100; cout<<"Enter the name of player 1"<<"\n"; cin>>n; cout<<"enter the name of player 2"<<"\n"; cin>>n2; char fs,ls,lc,fc; vector<int> ar1(9); string st,ca,sy; st=removeT(getState(num2)); sy=removeT(getSymbol(num2)); ca=removeT(getCapital(num2)); for(int i=0;i<9;i++) { ar1[i]=i+1; } random_shuffle(ar1.begin(),ar1.end()); fs=st.at(0); fc=ca.at(0); ls=st.at(st.length()-1); lc=ca.at(ca.length()-1); int cnt=0; int i=1,j=0,g=0; string guess; do { if(num1==0) { if(i%2!=0) name=n; else name=n2; score=score1; } else { if(i%2!=0) name=n2; else name=n; score=score2; } cout<<"Clue#"<<i; switch(ar1[j++]) { case 1: cout<<"for "<<name<<" is "<<"the first letter of the state is "<<fs<<"\n"; break; case 2: cout<<"for "<<name<<" is "<<"the last letter of the state is "<<ls<<"\n"; break; case 3: cout<<"for "<<name<<" is "<<"the first letter of the capital is "<<fc<<"\n"; break; case 4: cout<<"for "<<name<<" is "<<"the last letter of the capital is "<<lc<<"\n"; break; case 5: cout<<"for "<<name<<" is "<<"The state’s rank in population, where 1 is the largest, is "<<getPop(num2)<<"\n"; break; case 6: cout<<"for "<<name<<" is "<<"The state’s rank in size (or area), where 1 is the largest, is "<<getSize(num2)<<"\n"; break; case 7: cout<<"for "<<name<<" is "<<"The state is in the following time zone(s) "<<getZone(num2)<<"\n"; break; case 8: cout<<"for "<<name<<" is "<<"The state’s nickname is "<<getNick(num2)<<"\n"; break; case 9: cout<<"for "<<name<<" is "<<"The state is bordered by the following states: "<<getborState(num2)<<"\n"; break; } cout<<"Current Score "<<getScore()<<"\n"; cout<<"Would you like to guess the state (1) or do you want another clue (2)? "<<"\n"; cin>>g; if(g==2) { if(i%2!=0) { score1=score1-5; score=score1; } else { score2=score2-5; score=score2; } } else if(g==1) { cout<<"Enter your guess name or symbol"<<"\n"; cin>>guess; if((st.compare(guess)==0) || (sy.compare(guess)==0)) { cnt=1; cout<<"Correct! Congratulations! Your final score "<<getScore()<<"\n"; } else { if(i%2!=0) { score1=score1-5; score=score1; } else { score2=score2-5; score=score2; } cout<<"Incorrect. Current Score: "<<getScore()<<"\n"; } } i++; if(i>9) j=0; }while(cnt==0 && score!=0); if(cnt==1) { myfile.open ("output.txt",ios :: app); myfile << getState(num2)<<"\t"<<getScore()<<"\n"; myfile.close(); } return getScore(); } int main() { int c=0,cnt=0,t_score=0,tem; char ch,chr='Y'; double av; int num1=rand()%2; StateGame ob; do{ srand(time(0)); int num2=rand()%50; cout<<"Welcome to the Name The State Game!"<<"\n"; cout<<"would you like the rules of the game (Y or N)"<<"\n"; cin>>ch; if(ch=='N') cout<<"Lets get started . a state has been randomly selected. here is your first clue"<<"\n"; else cout<<"You have to guess the state name using the hints given.with every pass and wrong answer your score will be deducted by 5"<<"\n"; cout<<"You want to play 1-player (1) or 2-player (2)"<<"\n"; cin>>c; if(c==1) tem=ob.check(num2); else if(c==2) tem=ob.check1(num2,num1); cnt++; cout<<"Do you want to play again (Y | N)"<<"\n"; cin>>chr; t_score=t_score+tem; }while(chr=='Y' && cnt < 5); ifstream in("output.txt"); int cc=1; string line; if (in.is_open()) { for (int lineno = 0; getline (in,line); lineno++) { cout<<line<<"\n"; cc++; } in.close(); } av=t_score/cc; cout<<"You have played "<<cc<<" gamess and average is "<<av<<"\n"; getch(); return 0; }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Exchange Exploit
JavaScript | 2 sec ago | 0.32 KB
? Exploit 500$ in 15 Minutes
Java | 5 sec ago | 0.06 KB
⭐Crypto Exchange Profit Method⭐ C
JavaScript | 7 sec ago | 0.31 KB
Swapzone Glitch ⭐Working⭐
JavaScript | 8 sec ago | 0.32 KB
✅ MAKE $900 INSTANTLY
JavaScript | 13 sec ago | 0.32 KB
? Make $15OO in 2O minutesV E
Java | 15 sec ago | 0.06 KB
? Crypto Accounts
Java | 17 sec ago | 0.09 KB
⭐ Free ETH Method ⭐
JavaScript | 20 sec ago | 0.32 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!