• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 22:05
CET 04:05
KST 12:05
  • 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
Behind the Blue - Team Liquid History Book15Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8herO wins SC2 All-Star Invitational14
Community News
LiuLi Cup: 2025 Grand Finals (Feb 10-16)4Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker7PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)11Weekly Cups (Jan 26-Feb 1): herO, Clem, ByuN, Classic win2
StarCraft 2
General
Behind the Blue - Team Liquid History Book Weekly Cups (Jan 12-18): herO, MaxPax, Solar win How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Rongyi Cup S3 - Preview & Info Nexon's StarCraft game could be FPS, led by UMS maker
Tourneys
LiuLi Cup: 2025 Grand Finals (Feb 10-16) Sparkling Tuna Cup - Weekly Open Tournament PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) RSL Season 4 announced for March-April WardiTV Mondays
Strategy
Custom Maps
Modalert 200 for Focus and Alertness Map Editor closed ? [A] Starcraft Sound Mod
External Content
Mutation # 512 Overclocked The PondCast: SC2 News & Results Mutation # 511 Temple of Rebirth Mutation # 510 Safety Violation
Brood War
General
[ASL21] Potential Map Candidates BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft player reflex TE scores Gypsy to Korea
Tourneys
Escore Tournament StarCraft Season 1 [Megathread] Daily Proleagues Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Fighting Spirit mining rates Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta
Other Games
General Games
Diablo 2 thread Battle Aces/David Kim RTS Megathread Nintendo Switch Thread ZeroSpace Megathread EVE Corporation
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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 Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Ask and answer stupid questions here! Sex and weight loss YouTube Thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
Play, Watch, Drink: Esports …
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2360 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 States24753 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
Replay Cast
00:00
HomeStory Cup 28 - Group A
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 220
NeuroSwarm 83
Vindicta 34
StarCraft: Brood War
Shuttle 1959
NaDa 46
Noble 30
League of Legends
JimRising 648
C9.Mang0358
Counter-Strike
tarik_tv4751
Coldzera 871
taco 785
m0e_tv300
minikerr14
Super Smash Bros
hungrybox516
Mew2King60
Other Games
summit1g6344
Day[9].tv1083
Maynarde100
ViBE62
ZombieGrub14
PiLiPiLi8
Liquid`Ken2
Organizations
Other Games
gamesdonequick1300
BasetradeTV52
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Hupsaiya 75
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4377
• Stunt465
Other Games
• Day9tv1083
Upcoming Events
The PondCast
6h 55m
KCM Race Survival
6h 55m
LiuLi Cup
7h 55m
Scarlett vs TriGGeR
ByuN vs herO
Replay Cast
20h 55m
Online Event
1d 6h
LiuLi Cup
1d 7h
Serral vs Zoun
Cure vs Classic
Big Brain Bouts
1d 13h
Serral vs TBD
RSL Revival
1d 23h
RSL Revival
2 days
LiuLi Cup
2 days
[ Show More ]
uThermal 2v2 Circuit
2 days
RSL Revival
2 days
Replay Cast
2 days
Sparkling Tuna Cup
3 days
LiuLi Cup
3 days
Replay Cast
3 days
Replay Cast
4 days
LiuLi Cup
4 days
Wardi Open
4 days
Monday Night Weeklies
4 days
OSC
4 days
WardiTV Winter Champion…
5 days
Replay Cast
6 days
WardiTV Winter Champion…
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-02-10
Rongyi Cup S3
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
LiuLi Cup: 2025 Grand Finals
Nations Cup 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W8
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 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.