• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:38
CEST 08:38
KST 15:38
  • 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
HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6Code S RO8 Preview: herO, Zoun, Bunny, Classic7
Community News
Weekly Cups (June 23-29): Reynor in world title form?6FEL Cracov 2025 (July 27) - $8000 live event13Esports World Cup 2025 - Final Player Roster14Weekly Cups (June 16-22): Clem strikes back1Weekly Cups (June 9-15): herO doubles on GSL week4
StarCraft 2
General
StarCraft Mass Recall: SC1 campaigns on SC2 thread The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 FEL Cracov 2025 (July 27) - $8000 live event $200 Biweekly - StarCraft Evolution League #1
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers [G] Darkgrid Layout
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest ASL20 Preliminary Maps Unit and Spell Similarities
Tourneys
[BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [Megathread] Daily Proleagues [BSL20] ProLeague LB Final - Saturday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Effective Commercial Building Cost Assessment Tips Trading/Investing Thread US Politics Mega-thread Stop Killing Games - European Citizens Initiative Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
Game Sound vs. Music: The Im…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 569 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 States24664 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
Next event in 4h 22m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft410
mcanning 147
StarCraft: Brood War
Larva 653
TY 485
Noble 12
Hm[arnc] 4
Bale 3
Britney 0
Dota 2
febbydoto37
League of Legends
JimRising 641
Counter-Strike
summit1g7775
Stewie2K832
Other Games
shahzam1030
KnowMe144
NeuroSwarm55
Mew2King41
Organizations
Other Games
gamesdonequick832
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1589
• Stunt544
Upcoming Events
Wardi Open
4h 22m
PiGosaur Monday
17h 22m
The PondCast
1d 3h
Replay Cast
1d 17h
RSL Revival
2 days
ByuN vs Classic
Clem vs Cham
WardiTV European League
2 days
Replay Cast
2 days
RSL Revival
3 days
herO vs SHIN
Reynor vs Cure
WardiTV European League
3 days
FEL
3 days
[ Show More ]
Korean StarCraft League
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
FEL
4 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL: ProLeague
5 days
Dewalt vs Bonyth
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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 © 2025 TLnet. All Rights Reserved.