• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 01:02
CEST 07:02
KST 14:02
  • 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
Team TLMC #5 - Finalists & Open Tournaments0[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29LiuLi Cup - September 2025 Tournaments3
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (Sept 8-14): herO & MaxPax split cups Team Liquid Map Contest #21 - Presented by Monster Energy SpeCial on The Tasteless Podcast Team TLMC #5 - Finalists & Open Tournaments
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris SC4ALL $6,000 Open LAN in Philadelphia Sparkling Tuna Cup - Weekly Open Tournament WardiTV TL Team Map Contest #5 Tournaments RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
[ASL20] Ro16 Preview Pt2: Turbulence BW General Discussion ASL20 General Discussion Diplomacy, Cosmonarchy Edition BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro16 Group D [ASL20] Ro16 Group C [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Borderlands 3
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1109 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 States24701 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
PiGosaur Monday
00:00
#49
Liquipedia
OSC
23:00
OSC Elite Rising Star #16
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft556
StarCraft: Brood War
Leta 533
Noble 51
ajuk12(nOOB) 43
Icarus 10
Dota 2
NeuroSwarm138
Counter-Strike
Stewie2K448
semphis_45
Super Smash Bros
Mew2King40
Other Games
summit1g4980
C9.Mang0320
XaKoH 150
ViBE142
SortOf52
Trikslyr34
trigger0
Organizations
Other Games
gamesdonequick684
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• OhrlRock 91
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1125
• Rush1120
• Stunt434
Other Games
• Scarra1215
Upcoming Events
LiuLi Cup
5h 58m
OSC
13h 58m
RSL Revival
1d 4h
Maru vs Reynor
Cure vs TriGGeR
The PondCast
1d 7h
RSL Revival
2 days
Zoun vs Classic
Korean StarCraft League
2 days
BSL Open LAN 2025 - War…
3 days
RSL Revival
3 days
BSL Open LAN 2025 - War…
4 days
RSL Revival
4 days
[ Show More ]
Online Event
4 days
Wardi Open
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
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

Upcoming

2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
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.