• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:58
CET 18:58
KST 02:58
  • 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
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement
Brood War
General
What are former legends up to these days? BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason Path of Exile
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 Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread 12 Days of Starcraft The Games Industry And ATVI Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2106 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 States24751 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 2m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SpeCial 169
BRAT_OK 128
trigger 83
DivinesiaTV 64
MindelVK 33
JuggernautJason6
Railgan 0
StarCraft: Brood War
Britney 21935
Sea 2151
Mini 673
EffOrt 581
Shuttle 492
GuemChi 336
Light 221
Hyuk 163
hero 117
ggaemo 102
[ Show more ]
Rush 96
Hyun 63
PianO 61
Mind 43
910 38
Sexy 31
Pusan 23
HiyA 13
Shine 11
NaDa 4
Dota 2
Fuzer 530
Counter-Strike
pashabiceps676
Heroes of the Storm
Liquid`Hasu323
Other Games
Grubby6607
FrodaN5540
B2W.Neo390
RotterdaM191
ArmadaUGS150
XaKoH 100
Mew2King75
Organizations
Other Games
gamesdonequick184
StarCraft 2
WardiTV136
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• 3DClanTV 72
• StrangeGG 39
• HeavenSC 31
• Kozan
• Migwel
• AfreecaTV YouTube
• intothetv
• sooper7s
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• blackmanpl 39
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• lizZardDota2210
• Ler104
League of Legends
• Jankos2226
Other Games
• Shiphtur239
Upcoming Events
OSC
2m
BSL 21
2h 2m
Cross vs Dewalt
Replay Cast
15h 2m
Wardi Open
18h 2m
OSC
1d 18h
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
4 days
Korean StarCraft League
5 days
OSC
5 days
OSC
6 days
OSC
6 days
[ Show More ]
uThermal 2v2 Circuit
6 days
Liquipedia Results

Completed

Escore Tournament S1: W1
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
CSL Season 19: Qualifier 2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W2
Escore Tournament S1: W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
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.