• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:25
CEST 04:25
KST 11:25
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro24 Preview Pt2: News Flash8[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy16ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20
Community News
Weekly Cups (March 23-29): herO takes triple6Aligulac acquired by REPLAYMAN.com/Stego Research8Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool49Weekly Cups (March 9-15): herO, Clem, ByuN win4
StarCraft 2
General
Team Liquid Map Contest #22 - Presented by Monster Energy Aligulac acquired by REPLAYMAN.com/Stego Research Weekly Cups (March 23-29): herO takes triple What mix of new & old maps do you want in the next ladder pool? (SC2) herO wins SC2 All-Star Invitational
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April StarCraft Evolution League (SC Evo Biweekly) WardiTV Mondays World University TeamLeague (500$+) | Signups Open
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
Mutation # 519 Inner Power The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat
Brood War
General
ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Behind the scenes footage of ASL21 Group E A cwal.gg Extension - Easily keep track of anyone BW General Discussion
Tourneys
[ASL21] Ro24 Group F [ASL21] Ro24 Group E Azhi's Colosseum - Foreign KCM 🌍 Weekly Foreign Showmatches
Strategy
Fighting Spirit mining rates What's the deal with APM & what's its true value Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Starcraft Tabletop Miniature Game General RTS Discussion Thread Darkest Dungeon
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread The Games Industry And ATVI European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 10623 users

[H]C++ problem pt2

Blogs > fusionsdf
Post a Reply
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
Last Edited: 2008-03-27 23:57:06
March 27 2008 23:55 GMT
#1
I dont really expect an answer because this program is starting to get quite large, but Im getting desperate

This compiles fine, but gives the wrong output.

Basically its a bowling program.

It reads in an appropriate score (in the proper range), determines if its a normal, spare, strike or whatever and adds it to either playerA or player B's score (Player A always goes first)

it uses a sliding weight scale to calculate the score

To illustrate this (if you already understand what Im trying to do, you can skip this part).
A strike adds the next two bowls to this score (standard 10 pin rules), and a spare adds the next bowl to this score.
An example score for a one person game might be

In standard terms it might look like:
10---10 + 10 + 10
10---10 + 10 + 7
10---10 + 7 + 2
7 --- 7
2 --- 2
3 --- 3
4 --- 4
.
.
.
Total score 92. This can also be expressed as:
10 Weight1 = 1, weight2 = 1, score = 10 * 1 = 10
10 Weight1 = 2, weight2 = 2, score = 10 * 2 = 20
10 Weight1 = 3, weight2 = 2, score = 10 * 3 = 30
7 Weight1 = 3, weight2 = 2, score = 7 * 3 = 21
2 Weight1 = 2, weight2 = 1, score = 2 * 2 = 4
3 Weight1 = 1, weight2 = 1, score = 3 * 1 = 3
4 Weight1 = 1, weight2 = 1, score = 4 * 1 = 4
which of course also give 92.

This algorithm is basically what I'm trying to put in my program and adapt to two person play.

I have a bowl function that returns a status number: 1 for normal, 2 for spare, 3 for strike, 4 for in progress (frame isnt over for that player yet) which I use a lot.

Any help, questions or guidance?
Is my code poorly organized?
where is the mistake?

I am doing this for an assignment, so please dont write code for me (since I would rather not get kicked out of college) but any good faith things like, 'you have these two things in the wrong order' should be fine.

thanks to anyone at all who can help, even if its just a little bit.

If the lack of whitespace makes it hard to read, you can always quote me and look at it there.

#include <iostream>

using namespace std;

bool readScore(int &thisScore, int &errorCount);
int bowl(int &pins, int &thisScore, int &frames, int weight1);
void calcScore(int &thisScore, int weight1);
void incrementWeight(int &weight1, int &weight2);
void updateWeight(int status, int &weight1, int &weight2);
void addScore(char player, int thisScore, int &scoreA, int &scoreB);
void playerSwitch(int status, char &player, int &pins, int &frames);
void weightSwitch(int status, int &weight1, int &weight2, int &weight1PH, int &weight2PH);


int main() {

int thisScore = 0, errorCount = 0, pins = 10, frames = 0;
int weight1 = 1, weight2 = 1, weight1PH = 1, weight2PH = 1;
int status = 5;
int scoreA = 0, scoreB = 0;
char player = 'A';



while(frames < 10) {


readScore(thisScore, errorCount);
status = bowl(pins, thisScore, frames, weight1);


cout << "------------------------------------" << endl;
cout << "pins1: " << pins << endl;
cout << "ThisScore: " << thisScore << endl;
cout << "Error Count: " << errorCount << endl;
cout << "Pins: " << pins << endl;
cout << "Frames: " << frames << endl;
cout << "Status: " << status << endl;
cout << "Weight1: " << weight1 << endl;
cout << "Weight2: " << weight2 << endl;
cout << "ScoreA: " << scoreA << endl;
cout << "ScoreB: " << scoreB << endl;
cout << "Player: " << player << endl;
cout << "------------------------------------" << endl;


incrementWeight(weight1, weight2);
updateWeight(status, weight1, weight2);
addScore(player, thisScore, scoreA, scoreB);
playerSwitch(status, player, pins, frames);
weightSwitch(status, weight1, weight2, weight1PH, weight2PH);


cout << "ThisScore: " << thisScore << endl;
cout << "Error Count: " << errorCount << endl;
cout << "Pins: " << pins << endl;
cout << "Frames: " << frames << endl;
cout << "Status: " << status << endl;
cout << "Weight1: " << weight1 << endl;
cout << "Weight2: " << weight2 << endl;
cout << "ScoreA: " << scoreA << endl;
cout << "ScoreB: " << scoreB << endl;
cout << "Player: " << player << endl;

}


return 0;
}

bool readScore(int &thisScore, int &errorCount) {

cin >> thisScore;
return 1;
}


int bowl(int &pins, int &thisScore, int &frames, int weight1) {
//Determines if score in range and updates pins accordingly
//0 = error
//1 = normal
//2 = spare
//3 = strike
//4 = in progress


if (thisScore < 0 || thisScore > 10 || pins < 0){
//ERROR
return 0;
} else {
if (pins == 10) { //First Half
if (thisScore == 10) { //Strike
pins -= thisScore;
calcScore(thisScore, weight1);
return 3;
} else { //continue frame
pins -= thisScore;
calcScore(thisScore, weight1);
return 4;
}
} else { //Second Half
if ((pins + thisScore) == 10) { //Spare
pins -= thisScore;
calcScore(thisScore, weight1);
return 2;
} else { //Normal
pins -= thisScore;
calcScore(thisScore, weight1);
return 1;
}
}
}
}

void calcScore(int &thisScore, int weight1) {
thisScore *= weight1;
}


void incrementWeight(int &weight1, int &weight2) {
weight1 = weight2;
weight2 = 1;
}

void updateWeight(int status, int &weight1, int &weight2) {
if (status == 3) { //Strike
weight1 += 1;
weight2 += 1;
} else if (status == 2) { //Spare
weight1 += 1;
} else {
//do nothing
}
}

void addScore(char player, int thisScore, int &scoreA, int &scoreB) {
if (player == 'A') {
scoreA += thisScore;
} else {
scoreB += thisScore;
}
}

void playerSwitch(int status, char &player, int &pins, int &frames) {
if (status == 1 || status == 2 || status == 3) {
if (player == 'A') {
pins = 10;
player = 'B';
} else {
pins = 10;
player = 'A';
frames++;
}
} else {
//do nothing
}
}

void weightSwitch(int status, int &weight1, int &weight2, int &weight1PH, int &weight2PH) {
int tempWeight1, tempWeight2;

if (status == 1 || status == 2 || status == 3) {


tempWeight1 = weight1;
tempWeight2 = weight2;
weight1 = weight1PH;
weight2 = weight2PH;
weight1PH = tempWeight1;
weight2PH = tempWeight2;
}
}


SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
micronesia
Profile Blog Joined July 2006
United States24767 Posts
Last Edited: 2008-03-28 01:07:15
March 28 2008 01:04 GMT
#2
In before non-bowlers.

I'll actually read it now and edit lol.

Edit: maybe it's a while since I've done work in C++ but I'm not sure what your problem is... can you clarify?
ModeratorThere are animal crackers for people and there are people crackers for animals.
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
March 28 2008 01:16 GMT
#3
First you can see that the score boundaries arent working
second, the weights arent being properly transferred between players (each player should have their own set of weight [it doesnt make sense for player B to benefit from player A's strike for instance]) but right now they seem to be shared somehow....

my basic problem is that I dont get the proper score as well

so boundaries, weight transfer and scores dont work.

I'm pretty sure that the score is being calculated right, I think the problem is when I actually try to assign the score to one of the players, the score and weights are off


10
------------------------------------
pins1: 0
ThisScore: 10
Error Count: 0
Pins: 0
Frames: 0
Status: 3
Weight1: 1
Weight2: 1
ScoreA: 0
ScoreB: 0
Player: A
------------------------------------
ThisScore: 10
Error Count: 0
Pins: 10
Frames: 0
Status: 3
Weight1: 1
Weight2: 1
ScoreA: 10
ScoreB: 0
Player: B


10
------------------------------------
pins1: 0
ThisScore: 10
Error Count: 0
Pins: 0
Frames: 0
Status: 3
Weight1: 1
Weight2: 1
ScoreA: 10
ScoreB: 0
Player: B
------------------------------------
ThisScore: 10
Error Count: 0
Pins: 10
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 10
ScoreB: 10
Player: A



10
------------------------------------
pins1: 0
ThisScore: 20
Error Count: 0
Pins: 0
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 10
ScoreB: 10
Player: A
------------------------------------
ThisScore: 20
Error Count: 0
Pins: 10
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 30
ScoreB: 10
Player: B



2
------------------------------------
pins1: 8
ThisScore: 4
Error Count: 0
Pins: 8
Frames: 1
Status: 4
Weight1: 2
Weight2: 2
ScoreA: 30
ScoreB: 10
Player: B
------------------------------------
ThisScore: 4
Error Count: 0
Pins: 8
Frames: 1
Status: 4
Weight1: 2
Weight2: 1
ScoreA: 30
ScoreB: 14
Player: B



12
------------------------------------
pins1: 8
ThisScore: 12
Error Count: 0
Pins: 8
Frames: 1
Status: 0
Weight1: 2
Weight2: 1
ScoreA: 30
ScoreB: 14
Player: B
------------------------------------
ThisScore: 12
Error Count: 0
Pins: 8
Frames: 1
Status: 0
Weight1: 1
Weight2: 1
ScoreA: 30
ScoreB: 26
Player: B



5
------------------------------------
pins1: 3
ThisScore: 5
Error Count: 0
Pins: 3
Frames: 1
Status: 1
Weight1: 1
Weight2: 1
ScoreA: 30
ScoreB: 26
Player: B
------------------------------------
ThisScore: 5
Error Count: 0
Pins: 10
Frames: 2
Status: 1
Weight1: 3
Weight2: 2
ScoreA: 30
ScoreB: 31
Player: A



68
------------------------------------
pins1: 10
ThisScore: 68
Error Count: 0
Pins: 10
Frames: 2
Status: 0
Weight1: 3
Weight2: 2
ScoreA: 30
ScoreB: 31
Player: A
------------------------------------
ThisScore: 68
Error Count: 0
Pins: 10
Frames: 2
Status: 0
Weight1: 2
Weight2: 1
ScoreA: 98
ScoreB: 31
Player: A

SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
Elements
Profile Joined September 2007
United States13 Posts
Last Edited: 2008-03-28 01:34:14
March 28 2008 01:22 GMT
#4
Oh dear.....

Well after looking through it once the one thing wrong that i see is:

On March 28 2008 08:55 fusionsdf wrote:
...
} else {
if (pins == 10) { //First Half
if (thisScore == 10) { //Strike
...


When pins is 10 it could also mean that the guy missed the first bowl completely. you could use if (status != 4) instead of if (pins == 10)

EDIT: saw your post.
Okay, so what are you hoping happens when you enter an out-of-bounds score? Because you set status to 0 but then you don't output an error message or anything.
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
Last Edited: 2008-03-28 02:20:09
March 28 2008 02:19 GMT
#5
On March 28 2008 10:22 Elements wrote:

EDIT: saw your post.
Okay, so what are you hoping happens when you enter an out-of-bounds score? Because you set status to 0 but then you don't output an error message or anything.


ugh....guess Ive been looking at the code for too long



10
------------------------------------
pins1: 0
ThisScore: 10
Error Count: 0
Pins: 0
Frames: 0
Status: 3
Weight1: 1
Weight2: 1
ScoreA: 0
ScoreB: 0
Player: A
------------------------------------
ThisScore: 10
Error Count: 0
Pins: 10
Frames: 0
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 10
ScoreB: 0
Player: B
thisScore and scoreA are both correct, pins are right, weight is right. players switch


10
------------------------------------
pins1: 0
ThisScore: 10
Error Count: 0
Pins: 0
Frames: 0
Status: 3
Weight1: 1
Weight2: 1
ScoreA: 10
ScoreB: 0
Player: B
------------------------------------
ThisScore: 10
Error Count: 0
Pins: 10
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 10
ScoreB: 10
Player: A
everything ok here too. frames increment correctly.


10
------------------------------------
pins1: 0
ThisScore: 20
Error Count: 0
Pins: 0
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 10
ScoreB: 10
Player: A
------------------------------------
ThisScore: 20
Error Count: 0
Pins: 10
Frames: 1
Status: 3
Weight1: 3
Weight2: 2
ScoreA: 30
ScoreB: 10
Player: B
weight is right, so is score (10x2), weight updates properly. no problems I can see.


10
------------------------------------
pins1: 0
ThisScore: 20
Error Count: 0
Pins: 0
Frames: 1
Status: 3
Weight1: 2
Weight2: 2
ScoreA: 30
ScoreB: 10
Player: B
------------------------------------
ThisScore: 20
Error Count: 0
Pins: 10
Frames: 2
Status: 3
Weight1: 3
Weight2: 2
ScoreA: 30
ScoreB: 30
Player: A

again all correct

4
------------------------------------
pins1: 6
ThisScore: 12
Error Count: 0
Pins: 6
Frames: 2
Status: 4
Weight1: 3
Weight2: 2
ScoreA: 30
ScoreB: 30
Player: A
------------------------------------
ThisScore: 12
Error Count: 0
Pins: 6
Frames: 2
Status: 4
Weight1: 2
Weight2: 1
ScoreA: 42
ScoreB: 30
Player: A

this is correct, status is 4, frame still in play for A, weight updates properly

4
------------------------------------
pins1: 2
ThisScore: 8
Error Count: 0
Pins: 2
Frames: 2
Status: 2
Weight1: 2
Weight2: 1
ScoreA: 42
ScoreB: 30
Player: A
------------------------------------
ThisScore: 8
Error Count: 0
Pins: 10
Frames: 2
Status: 2
Weight1: 2
Weight2: 1
ScoreA: 50
ScoreB: 30
Player: B
[weights are correct


4
------------------------------------
pins1: 6
ThisScore: 12
Error Count: 0
Pins: 6
Frames: 2
Status: 4
Weight1: 3
Weight2: 2
ScoreA: 50
ScoreB: 30
Player: B
------------------------------------
ThisScore: 12
Error Count: 0
Pins: 6
Frames: 2
Status: 4
Weight1: 2
Weight2: 1
ScoreA: 50
ScoreB: 42
Player: B



4
------------------------------------
pins1: 2
ThisScore: 8
Error Count: 0
Pins: 2
Frames: 2
Status: 2
Weight1: 2
Weight2: 1
ScoreA: 50
ScoreB: 42
Player: B
------------------------------------
ThisScore: 8
Error Count: 0
Pins: 10
Frames: 3
Status: 2
Weight1: 2
Weight2: 1
ScoreA: 50
ScoreB: 50
Player: A
HERE is the problem. incoming weight is correct, outgoing should be 1,1. status is also wrong. This isnt a spare, its a normal. Status should be 1.


4
------------------------------------
pins1: 6
ThisScore: 8
Error Count: 0
Pins: 6
Frames: 3
Status: 4
Weight1: 2
Weight2: 1
ScoreA: 50
ScoreB: 50
Player: A
------------------------------------
ThisScore: 8
Error Count: 0
Pins: 6
Frames: 3
Status: 4
Weight1: 1
Weight2: 1
ScoreA: 58
ScoreB: 50
Player: A

and we see the result here. ScoreA should be 54 not 58. outgoing weight is now correct....

SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
Elements
Profile Joined September 2007
United States13 Posts
Last Edited: 2008-03-28 03:11:24
March 28 2008 03:07 GMT
#6
lol
ok this isn't right: if ((pins + thisScore) == 10) { //Spare
should be + Show Spoiler +
if (pins == thisScore)


EDIT: speaking of that you should probably change the out of bounds checker to thisScore > pins as opposed to 10
haduken
Profile Blog Joined April 2003
Australia8267 Posts
March 28 2008 08:06 GMT
#7
errr headache headache headache
Rillanon.au
Please log in or register to reply.
Live Events Refresh
PSISTORM Gaming Misc
00:30
FSL s10 retrospective
Liquipedia
OSC
00:00
OSC Elite Rising Star #18
CranKy Ducklings84
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft364
ViBE192
RuFF_SC2 121
CosmosSc2 33
StarCraft: Brood War
GuemChi 6292
Artosis 617
Shuttle 372
NaDa 29
Terrorterran 2
Dota 2
NeuroSwarm55
monkeys_forever17
Counter-Strike
summit1g12903
C9.Mang0305
Other Games
tarik_tv3406
JimRising 411
Organizations
Other Games
gamesdonequick1068
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• Berry_CruncH167
• Hupsaiya 81
• EnkiAlexander 24
• davetesta17
• CranKy Ducklings SOOP4
• intothetv
• Kozan
• AfreecaTV YouTube
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 25
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt255
Upcoming Events
RSL Revival
7h 35m
TriGGeR vs Cure
ByuN vs Rogue
Big Brain Bouts
13h 35m
Replay Cast
21h 35m
RSL Revival
1d 7h
Maru vs MaxPax
BSL
1d 16h
RSL Revival
2 days
uThermal 2v2 Circuit
2 days
BSL
2 days
Afreeca Starleague
3 days
Replay Cast
3 days
[ Show More ]
Sparkling Tuna Cup
4 days
The PondCast
6 days
Replay Cast
6 days
Liquipedia Results

Completed

CSL Season 20: Qualifier 1
WardiTV Winter 2026
NationLESS Cup

Ongoing

BSL Season 22
CSL Elite League 2026
ASL Season 21
CSL Season 20: Qualifier 2
Escore Tournament S2: W1
StarCraft2 Community Team League 2026 Spring
RSL Revival: Season 4
Nations Cup 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026

Upcoming

CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.