Calling Senti, Chico, moqvda (C++ programmers)

Maximagq

Banned
For this code, I am having trouble once a player gets the Advantage score and the other player gets it back to Deuce. I wrote this hastily so yeah haha

Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void getSetScore(int& setScoreP1, int& setScoreP2)
{
	cout << setScoreP1 << endl;
	cout << setScoreP2 << endl;
}

void getGameScore(int& gameScoreP1, int& gameScoreP2)
{
	cout << gameScoreP1 << endl;
	cout << gameScoreP2 << endl;
}

void getPointScore(int& pointScoreP1, int& pointScoreP2)
{
	cout << pointScoreP1 << endl;
	cout << pointScoreP2 << endl;
}

void getPointScoreAd(int& pointScore)
{
	if (pointScore == 1)
	{
		cout << "Ad" << endl;
		cout << endl;
	}

	else if (pointScore == 2)
	{
		cout << endl;
		cout << "Ad" << endl;
	}
}

class score
{
public:

private:
	int m_setScore;
	int m_gameScore;
	int m_pointScore;
};

int main()
{
	int setScoreP1 = 0, setScoreP2 = 0, gameScoreP1 = 0, gameScoreP2 = 0, pointScoreP1 = 0, pointScoreP2 = 0;
	bool deuce = false, AdP1 = false, AdP2 = false;

	int numOfSets;
	cout << "How many sets do you want to play (1, 3, or 5)?" << endl;
	while (true)
	{
		cin >> numOfSets;
		if (numOfSets != 1 && numOfSets != 3 && numOfSets != 5)
			cout << "Enter 1, 3, or 5" << endl;
		else
			break;
	}

	do
	{
		if (pointScoreP1 == 40 && pointScoreP2 == 40)
			deuce = true;

		if ((setScoreP1 != 0 || setScoreP2 != 0))
		{
			cout << "Set score" << endl;
			getSetScore(setScoreP1, setScoreP2);
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else if (gameScoreP1 != 0 || gameScoreP2 != 0)
		{
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else
		{
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}
		cout << endl << "Which player won the point (1 or 2): ";
		int input;
		cin >> input;
		if (input != 1 && input != 2)
		{
			cout << "Enter 1 or 2" << endl;
			continue;
		}

		if (deuce == true)
		{
			if (input == 1)
			{
				deuce = false;
				AdP1 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}

			else if (input == 2)
			{
				deuce = false;
				AdP2 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}
		}

		if (input == 1 && (pointScoreP1 == 0 || pointScoreP1 == 15))
			pointScoreP1 += 15, deuce = false;
		else if (input == 1 && pointScoreP1 == 30)
			pointScoreP1 += 10, deuce = false;
		else if (input == 1 && (pointScoreP1 == 40 && pointScoreP2 != 40) || (AdP1 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP1++;
			deuce = false;
			AdP1 = false;
		}
		else if (AdP1 == true && input == 2)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP1 = false;
		}
		else if (input == 2 && (pointScoreP2 == 0 || pointScoreP2 == 15))
			pointScoreP2 += 15, deuce = false;
		else if (input == 2 && pointScoreP2 == 30)
			pointScoreP2 += 10, deuce = false;
		else if (AdP2 == true && input == 1)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP2 = false;
		}
		else if (input == 2 && (pointScoreP2 == 40 && pointScoreP1 != 40 || AdP2 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP2++;
			deuce = false;
			AdP2 = false;
		}

		if ((gameScoreP1 >= 6 || gameScoreP2 >= 6) && abs(gameScoreP1 - gameScoreP2) > 1)
		{
			if (gameScoreP1 == 6)
			{
				setScoreP1++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			}
			else
			{
				setScoreP2++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			
			}
		}
		
		if (numOfSets == 1)
		{
			if (setScoreP1 == 1)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 1)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else if (numOfSets == 3)
		{
			if (setScoreP1 == 2)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 2)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else
		{
			if (setScoreP1 == 3)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			else if (setScoreP2 == 3)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}
	}
	while (true);
}
 
Last edited:

Maximagq

Banned
Sorry just noticed that copy and paste removes all the spacing and makes it almost informattable. Apologies :(
 

Maximagq

Banned
Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void getSetScore(int& setScoreP1, int& setScoreP2)
{
	cout << setScoreP1 << endl;
	cout << setScoreP2 << endl;
}

void getGameScore(int& gameScoreP1, int& gameScoreP2)
{
	cout << gameScoreP1 << endl;
	cout << gameScoreP2 << endl;
}

void getPointScore(int& pointScoreP1, int& pointScoreP2)
{
	cout << pointScoreP1 << endl;
	cout << pointScoreP2 << endl;
}

void getPointScoreAd(int& pointScore)
{
	if (pointScore == 1)
	{
		cout << "Ad" << endl;
		cout << endl;
	}

	else if (pointScore == 2)
	{
		cout << endl;
		cout << "Ad" << endl;
	}
}

class score
{
public:

private:
	int m_setScore;
	int m_gameScore;
	int m_pointScore;
};

int main()
{
	int setScoreP1 = 0, setScoreP2 = 0, gameScoreP1 = 0, gameScoreP2 = 0, pointScoreP1 = 0, pointScoreP2 = 0;
	bool deuce = false, AdP1 = false, AdP2 = false;

	int numOfSets;
	cout << "How many sets do you want to play (1, 3, or 5)?" << endl;
	while (true)
	{
		cin >> numOfSets;
		if (numOfSets != 1 && numOfSets != 3 && numOfSets != 5)
			cout << "Enter 1, 3, or 5" << endl;
		else
			break;
	}

	do
	{
		if (pointScoreP1 == 40 && pointScoreP2 == 40)
			deuce = true;

		if ((setScoreP1 != 0 || setScoreP2 != 0))
		{
			cout << "Set score" << endl;
			getSetScore(setScoreP1, setScoreP2);
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else if (gameScoreP1 != 0 || gameScoreP2 != 0)
		{
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else
		{
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}
		cout << endl << "Which player won the point (1 or 2): ";
		int input;
		cin >> input;
		if (input != 1 && input != 2)
		{
			cout << "Enter 1 or 2" << endl;
			continue;
		}

		if (deuce == true)
		{
			if (input == 1)
			{
				deuce = false;
				AdP1 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}

			else if (input == 2)
			{
				deuce = false;
				AdP2 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}
		}

		if (input == 1 && (pointScoreP1 == 0 || pointScoreP1 == 15))
			pointScoreP1 += 15, deuce = false;
		else if (input == 1 && pointScoreP1 == 30)
			pointScoreP1 += 10, deuce = false;
		else if (input == 1 && (pointScoreP1 == 40 && pointScoreP2 != 40) || (AdP1 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP1++;
			deuce = false;
			AdP1 = false;
		}
		else if (AdP1 == true && input == 2)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP1 = false;
		}
		else if (input == 2 && (pointScoreP2 == 0 || pointScoreP2 == 15))
			pointScoreP2 += 15, deuce = false;
		else if (input == 2 && pointScoreP2 == 30)
			pointScoreP2 += 10, deuce = false;
		else if (AdP2 == true && input == 1)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP2 = false;
		}
		else if (input == 2 && (pointScoreP2 == 40 && pointScoreP1 != 40 || AdP2 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP2++;
			deuce = false;
			AdP2 = false;
		}

		if ((gameScoreP1 >= 6 || gameScoreP2 >= 6) && abs(gameScoreP1 - gameScoreP2) > 1)
		{
			if (gameScoreP1 == 6)
			{
				setScoreP1++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			}
			else
			{
				setScoreP2++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			
			}
		}
		
		if (numOfSets == 1)
		{
			if (setScoreP1 == 1)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 1)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else if (numOfSets == 3)
		{
			if (setScoreP1 == 2)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 2)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else
		{
			if (setScoreP1 == 3)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			else if (setScoreP2 == 3)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}
	}
	while (true);
}
 

Maximagq

Banned
The class declaration isn't really doing anything right now but I was planning on making the functions as member functions and most of the variables as private data members.
 

Maximagq

Banned
Key things to note:
1. I am trying to get the output to look like the ones we see on ESPN etc, but I didn't have time to do the spacing correctly. This is why I have the function for the advantage scores but I didn't call it in main because I didn't implement it correctly.
2. It's primarily if, else-if, else conditionals which is hella convoluted and I want to make it more efficient and clear.
3. I didn't comment because I'm busy with Physics HW :(
 

kOaMaster

Hall of Fame
How about using "case" instead of your if/else-statements?
Especially for Ad1/deuce/Ad2. you can have a counter for each ad1/deuce/ad2 an set each counter to zero before beginning a new game.

From each case there are only two following outcomes possible...

->
case0-0:
cout 0-0
player 1 won the point: go to case15-0
player 2 won the point: go to case0-15
case15-0:
cout 15-0
player 1 won the point: go to case30-0
player 2 won the point: go to case15-15
case0-15:
etc.


edit: I'm not going to program this right now but these are just some suggestions. I'm not a huge fan of more than two interlaced if/else-statements. makes the code unreadable (and hard to debug)
 
Last edited:

Maximagq

Banned
How about using "case" instead of your if/else-statements?
Especially for Ad1/deuce/Ad2. you can have a counter for each ad1/deuce/ad2 an set each counter to zero before beginning a new game.

From each case there are only two following outcomes possible...

->
case0-0:
cout 0-0
player 1 won the point: go to case15-0
player 2 won the point: go to case0-15
case15-0:
cout 15-0
player 1 won the point: go to case30-0
player 2 won the point: go to case15-15
case0-15:
etc.


edit: I'm not going to program this right now but these are just some suggestions. I'm not a huge fan of more than two interlaced if/else-statements. makes the code unreadable (and hard to debug)

Hm so I should use a switch statement to use the keyword 'case'?
 

kOaMaster

Hall of Fame
yes. switch (variable)
and since switch does only work with integer afaik, you would have to build like a table for the statements (or convert your string to int with another function but that can think of later)
case 0 = 0-0
case 1 = 15-0
case 2 = 0-15

...
case 10 = deuce
case 11 = ad1
case 12 = ad2

case 20 = game1
case 21 = game2

case 30 = retired

default = invalid case

(or something equal)

ps: I'm not that advanced as a programmer. used to do some stuff professionally/for my studies but that was some time ago and I was better in having the ideas than coding ;)
 
Last edited:

Maximagq

Banned
Found the bug, code works fine I think but it still looks amateurish.

Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void getSetScore(int& setScoreP1, int& setScoreP2)
{
	cout << setScoreP1 << endl;
	cout << setScoreP2 << endl;
}

void getGameScore(int& gameScoreP1, int& gameScoreP2)
{
	cout << gameScoreP1 << endl;
	cout << gameScoreP2 << endl;
}

void getPointScore(int& pointScoreP1, int& pointScoreP2)
{
	cout << pointScoreP1 << endl;
	cout << pointScoreP2 << endl;
}

void getPointScoreAd(int& pointScore)
{
	if (pointScore == 1)
	{
		cout << "Ad" << endl;
		cout << endl;
	}

	else if (pointScore == 2)
	{
		cout << endl;
		cout << "Ad" << endl;
	}
}

class score
{
public:

private:
	int m_setScore;
	int m_gameScore;
	int m_pointScore;
};

int main()
{
	int setScoreP1 = 0, setScoreP2 = 0, gameScoreP1 = 0, gameScoreP2 = 0, pointScoreP1 = 0, pointScoreP2 = 0;
	bool deuce = false, AdP1 = false, AdP2 = false;

	int numOfSets;
	cout << "How many sets do you want to play (1, 3, or 5)?" << endl;
	while (true)
	{
		cin >> numOfSets;
		if (numOfSets != 1 && numOfSets != 3 && numOfSets != 5)
			cout << "Enter 1, 3, or 5" << endl;
		else
			break;
	}

	do
	{
		if (pointScoreP1 == 40 && pointScoreP2 == 40)
			deuce = true;

		if ((setScoreP1 != 0 || setScoreP2 != 0))
		{
			cout << "Set score" << endl;
			getSetScore(setScoreP1, setScoreP2);
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else if (gameScoreP1 != 0 || gameScoreP2 != 0)
		{
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else
		{
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}
		cout << endl << "Which player won the point (1 or 2): ";
		int input;
		cin >> input;
		if (input != 1 && input != 2)
		{
			cout << "Enter 1 or 2" << endl;
			continue;
		}

		if (deuce == true)
		{
			if (input == 1)
			{
				deuce = false;
				AdP1 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}

			else if (input == 2)
			{
				deuce = false;
				AdP2 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}
		}

		if (input == 1 && (pointScoreP1 == 0 || pointScoreP1 == 15))
			pointScoreP1 += 15, deuce = false;
		else if (input == 1 && pointScoreP1 == 30)
			pointScoreP1 += 10, deuce = false;
		else if (input == 1 && (pointScoreP1 == 40 && pointScoreP2 != 40 || AdP1 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP1++;
			deuce = false;
			AdP1 = false;
		}
		else if (AdP1 == true && input == 2)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP1 = false;
		}
		else if (input == 2 && (pointScoreP2 == 0 || pointScoreP2 == 15))
			pointScoreP2 += 15, deuce = false;
		else if (input == 2 && pointScoreP2 == 30)
			pointScoreP2 += 10, deuce = false;
		else if (AdP2 == true && input == 1)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP2 = false;
		}
		else if (input == 2 && (pointScoreP2 == 40 && pointScoreP1 != 40 || AdP2 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP2++;
			deuce = false;
			AdP2 = false;
		}

		if ((gameScoreP1 >= 6 || gameScoreP2 >= 6) && abs(gameScoreP1 - gameScoreP2) > 1)
		{
			if (gameScoreP1 == 6)
			{
				setScoreP1++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			}
			else
			{
				setScoreP2++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			
			}
		}
		
		if (numOfSets == 1)
		{
			if (setScoreP1 == 1)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 1)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else if (numOfSets == 3)
		{
			if (setScoreP1 == 2)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 2)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else
		{
			if (setScoreP1 == 3)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			else if (setScoreP2 == 3)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}
	}
	while (true);
}
 

Chico

Banned
No time to look at this closely now, sorry. Need to take deeper look in order to see what is wrong.

Couple of suggestions after a quick look
- As someone said use case statement rather than if/else.
- Create enums to use in case statements.
- Break the main into several separate functions. The code is messy and really difficult to follow.
- Add some comments in the code.
- Move all the code in the class and just call the class from main - i.e. OO approach. What you wrote here is C program in C++ syntax :)
- No need to declare basic types function parameters as references (int&) if they are input parameters only - i.e. you are not changing them. Big class type input only parameters (i.e. Score& for example) should be declared as const Score& as Suresh said.
- Use debugger to figure out why is your code not behaving as you intended. You can also add some debug logging to help you instead.
 
Last edited:

kOaMaster

Hall of Fame
there's still enough c++ around. just other uses. and there's a lot of c#...but the principles of c++ (and c) are still important enough to learn it in the beginning.
I started with pascal, qbasic, eiffel...
 
Last edited:

Sentinel

Bionic Poster
So sad, c++ is so dated.... It's all java now...
LOL, my dear chap, Java is dated too. People call it the Cobol of modern times (along with perhaps PHP).

Yes, C++ sucks, i haven't checked out C++ 11 or 14 or whatever's come out recently and don't intend to.

"D" was much better but never picked up traction. I hope Rust does well. Go has Google backing, so should do well.

Scala is much better than Java, and again, i am not following Java 8. That ship sailed ten years back.

But job-wise, so much has been written in C++ and Java that they are safe bets.
 

Chico

Banned
Too bad I have Sentinel on ignore due to his rude, insulting and unacceptable behavior in chocolate thread, because i have some nice things to say about Scala.

Next time.
 

idono1301

Semi-Pro
No time to look at this closely now, sorry. Need to take deeper look in order to see what is wrong.

Couple of suggestions after a quick look
- As someone said use case statement rather than if/else.
- Create enums to use in case statements.
- Break the main into several separate functions. The code is messy and really difficult to follow.
- Add some comments in the code.
- Move all the code in the class and just call the class from main - i.e. OO approach. What you wrote here is C program in C++ syntax :)
- No need to declare basic types function parameters as references (int&) if they are input parameters only - i.e. you are not changing them. Big class type input only parameters (i.e. Score& for example) should be declared as const Score& as Suresh said.
- Use debugger to figure out why is your code not behaving as you intended. You can also add some debug logging to help you instead.

Well said! I was thinking most of the same things.



As for the those who say that C/C++ are dated. I agree to a point, they can be very irritating to get it to do what you want. However, at least for the next few years, it will still be in demand for embedded systems.

On the broader view though, things will probably move towards domain specific languages (DSLs).

The above is just my opinion, it's great to see what everyone has to say :)
 

Sentinel

Bionic Poster
Too bad I have Sentinel on ignore due to his rude, insulting and unacceptable behavior in chocolate thread, because i have some nice things to say about Scala.

Next time.
You should have reported Senti for his unacceptable behavior.

What did Senti do ?
Seg-fault? Divide by zero ? Use undefined behavior as a compiler optimization ? Premature optimization ?

Or make an AbstractBeanFactoryVisitorFactory where a simple AbstractFactoryFactory would have done ?

But if it was the Chocolate thread he may have tried to run Lindt on some Javascript.

Or did he write an iOS app in Objective-C instead of Cocoa ? Did he run mocha on your java class?

What, dear Chico, did he do ?




..
 

The Green Mile

Bionic Poster
You should have reported Senti for his unacceptable behavior.

What did Senti do ?
Seg-fault? Divide by zero ? Use undefined behavior as a compiler optimization ? Premature optimization ?

Or make an AbstractBeanFactoryVisitorFactory where a simple AbstractFactoryFactory would have done ?

But if it was the Chocolate thread he may have tried to run Lindt on some Javascript.

Or did he write an iOS app in Objective-C instead of Cocoa ? Did he run mocha on your java class?

What, dear Chico, did he do ?




..

I'll quote it so Chico can see....ANSWER HIM!
 

Chico

Banned
You should have reported Senti for his unacceptable behavior.

What did Senti do ?
Seg-fault? Divide by zero ? Use undefined behavior as a compiler optimization ? Premature optimization ?

Or make an AbstractBeanFactoryVisitorFactory where a simple AbstractFactoryFactory would have done ?

But if it was the Chocolate thread he may have tried to run Lindt on some Javascript.

Or did he write an iOS app in Objective-C instead of Cocoa ? Did he run mocha on your java class?

What, dear Chico, did he do ?




..

I suggest you read this - Dealing with Failure in Actor Systems:

http://danielwestheide.com/blog/201...15-dealing-with-failure-in-actor-systems.html
 

Sentinel

Bionic Poster
I suggest you read this - Dealing with Failure in Actor Systems:

http://danielwestheide.com/blog/201...15-dealing-with-failure-in-actor-systems.html
Thanks, Chico.

No, he insulted and made fun of my whole nation in a quite xenophobic several comments. Not cool at all, indeed.

Just to clear the air, I did not insult any country in that thread and never have. You have totally misunderstood the word-play on Djokovic and chocolate. Maybe there is some nuance to chocolate or "ovic" that only you know of, none of us seem to.

So kindly get this notion out of your system that i insulted Serbia.
 

Chico

Banned
Thanks, Chico.



Just to clear the air, I did not insult any country in that thread and never have. You have totally misunderstood the word-play on Djokovic and chocolate. Maybe there is some nuance to chocolate or "ovic" that only you know of, none of us seem to.

So kindly get this notion out of your system that i insulted Serbia.

1. No problem.
2. Ok lets clear the air. I was offended by that comment, especially considering couple others that were posted by some other posters in the same thread too. The thread was turning into Serbian bashing. I asked you nicely to retract it and make it right, which you refused and continued to make fun on the same topic. I didn't appreciate what you did there regardless of what were your original intentions. I was quite disappointed since I had a lots of respect for you and thought you are a nice poster up to that point.

Now lets get back to discuss programming. Much more interesting topic.
It looks like Max is busy solving differential equations, so lost interest to finish this and make it right.
 

McMurphy

Banned
For this code, I am having trouble once a player gets the Advantage score and the other player gets it back to Deuce. I wrote this hastily so yeah haha

Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void getSetScore(int& setScoreP1, int& setScoreP2)
{
	cout << setScoreP1 << endl;
	cout << setScoreP2 << endl;
}

void getGameScore(int& gameScoreP1, int& gameScoreP2)
{
	cout << gameScoreP1 << endl;
	cout << gameScoreP2 << endl;
}

void getPointScore(int& pointScoreP1, int& pointScoreP2)
{
	cout << pointScoreP1 << endl;
	cout << pointScoreP2 << endl;
}

void getPointScoreAd(int& pointScore)
{
	if (pointScore == 1)
	{
		cout << "Ad" << endl;
		cout << endl;
	}

	else if (pointScore == 2)
	{
		cout << endl;
		cout << "Ad" << endl;
	}
}

class score
{
public:

private:
	int m_setScore;
	int m_gameScore;
	int m_pointScore;
};

int main()
{
	int setScoreP1 = 0, setScoreP2 = 0, gameScoreP1 = 0, gameScoreP2 = 0, pointScoreP1 = 0, pointScoreP2 = 0;
	bool deuce = false, AdP1 = false, AdP2 = false;

	int numOfSets;
	cout << "How many sets do you want to play (1, 3, or 5)?" << endl;
	while (true)
	{
		cin >> numOfSets;
		if (numOfSets != 1 && numOfSets != 3 && numOfSets != 5)
			cout << "Enter 1, 3, or 5" << endl;
		else
			break;
	}

	do
	{
		if (pointScoreP1 == 40 && pointScoreP2 == 40)
			deuce = true;

		if ((setScoreP1 != 0 || setScoreP2 != 0))
		{
			cout << "Set score" << endl;
			getSetScore(setScoreP1, setScoreP2);
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else if (gameScoreP1 != 0 || gameScoreP2 != 0)
		{
			cout << "Game score" << endl;
			getGameScore(gameScoreP1, gameScoreP2);
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}

		else
		{
			cout << "Point score" << endl;
			if (deuce == true)
				cout << "Deuce" << endl;
			else if (AdP1 == true)
				cout << "Advantage Player 1" << endl;
			else if (AdP2 == true)
				cout << "Advantage Player 2" << endl;
			else
				getPointScore(pointScoreP1, pointScoreP2);
		}
		cout << endl << "Which player won the point (1 or 2): ";
		int input;
		cin >> input;
		if (input != 1 && input != 2)
		{
			cout << "Enter 1 or 2" << endl;
			continue;
		}

		if (deuce == true)
		{
			if (input == 1)
			{
				deuce = false;
				AdP1 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}

			else if (input == 2)
			{
				deuce = false;
				AdP2 = true;
				pointScoreP1 = -1, pointScoreP2 = -1;
				continue;
			}
		}

		if (input == 1 && (pointScoreP1 == 0 || pointScoreP1 == 15))
			pointScoreP1 += 15, deuce = false;
		else if (input == 1 && pointScoreP1 == 30)
			pointScoreP1 += 10, deuce = false;
		else if (input == 1 && (pointScoreP1 == 40 && pointScoreP2 != 40) || (AdP1 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP1++;
			deuce = false;
			AdP1 = false;
		}
		else if (AdP1 == true && input == 2)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP1 = false;
		}
		else if (input == 2 && (pointScoreP2 == 0 || pointScoreP2 == 15))
			pointScoreP2 += 15, deuce = false;
		else if (input == 2 && pointScoreP2 == 30)
			pointScoreP2 += 10, deuce = false;
		else if (AdP2 == true && input == 1)
		{
			pointScoreP1 = -1;
			pointScoreP2 = -1;
			deuce = true;
			AdP2 = false;
		}
		else if (input == 2 && (pointScoreP2 == 40 && pointScoreP1 != 40 || AdP2 == true))
		{
			pointScoreP1 = 0;
			pointScoreP2 = 0;
			gameScoreP2++;
			deuce = false;
			AdP2 = false;
		}

		if ((gameScoreP1 >= 6 || gameScoreP2 >= 6) && abs(gameScoreP1 - gameScoreP2) > 1)
		{
			if (gameScoreP1 == 6)
			{
				setScoreP1++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			}
			else
			{
				setScoreP2++;
				gameScoreP1 = 0;
				gameScoreP2 = 0;
			
			}
		}
		
		if (numOfSets == 1)
		{
			if (setScoreP1 == 1)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 1)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else if (numOfSets == 3)
		{
			if (setScoreP1 == 2)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			
			else if (setScoreP2 == 2)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}

		else
		{
			if (setScoreP1 == 3)
			{
				cout << "Player 1 wins" << endl;
				break;
			}
			else if (setScoreP2 == 3)
			{
				cout << "Player 2 wins" << endl;
				break;
			}
		}
	}
	while (true);
}

Forget all the advice you got. You need to study "Structure and Interpretation of Computer Programs".

In Computer Science, knowing the syntax and constructs/idioms of a specific programming language is worthless. Especially if you don't know how to think about and approach the problem you are trying to solve.

Your code is a hideous mess because it has no clear structure or purpose, it is full of unnecessary repetition, etc. Learn to think clearly first about the problem, then code a clean solution.

Also, improving more abstract skills (vs learning how to hack code in a specific language) is something which will always stay with you and which you can apply to any language.
 

McMurphy

Banned
1. No problem.
2. Ok lets clear the air. I was offended by that comment, especially considering couple others that were posted by some other posters in the same thread too. The thread was turning into Serbian bashing. I asked you nicely to retract it and make it right, which you refused and continued to make fun on the same topic. I didn't appreciate what you did there regardless of what were your original intentions. I was quite disappointed since I had a lots of respect for you and thought you are a nice poster up to that point.

Now lets get back to discuss programming. Much more interesting topic.
It looks like Max is busy solving differential equations, so lost interest to finish this and make it right.

This gentleman didn't have a good day when he poasted this, apparently. :mad:
 

Sentinel

Bionic Poster
This gentleman didn't have a good day when he poasted this, apparently. :mad:

Unfortunately, that gentleman got banned, and it would appear for eternity which is not a very long time, since time has an end, if we go by The Theory of Everything.

Yeah, he put Tom and me in our "right places", we thank him profusely for exposing us as "pretentious snobs" and jerks. Where he is, we don't know, maybe in Zubrowska sitting in the Grand Budapest Hotel munching Mendl's.

Or wearing the "Lobby Boy" cap. :D
 

movdqa

Talk Tennis Guru
Forget all the advice you got. You need to study "Structure and Interpretation of Computer Programs".

In Computer Science, knowing the syntax and constructs/idioms of a specific programming language is worthless. Especially if you don't know how to think about and approach the problem you are trying to solve.

Your code is a hideous mess because it has no clear structure or purpose, it is full of unnecessary repetition, etc. Learn to think clearly first about the problem, then code a clean solution.

Also, improving more abstract skills (vs learning how to hack code in a specific language) is something which will always stay with you and which you can apply to any language.

I think that you can download SICP from MIT OCW or you can buy it from Amazon. CS students do need to spend a little time programming to get a feel as to why design is important. First-year assignments often look like a mess with lot of pieces "bolted on". You need a bigger project to convince students that they just can't start coding linearly.
 

McMurphy

Banned
I think that you can download SICP from MIT OCW or you can buy it from Amazon. CS students do need to spend a little time programming to get a feel as to why design is important. First-year assignments often look like a mess with lot of pieces "bolted on". You need a bigger project to convince students that they just can't start coding linearly.

Yes, exactly.

SICP is freely downloadable, and I also think somebody created a LaTeX facsimile which is freely downloadable as well.

It's nice that it uses Scheme instead of a messy language like C++ or Java, but unfortunately that has in recent years turned off a lot of people not familiar with functional programming languages. Functional programming seems to be enjoying some mainstream success lately though.
 

McMurphy

Banned
Oh I wrote this in like 2 hours so that's why it looks like crap haha. Thanks for the comments.

Haste is no excuse, but lack of experience is.

Consider this: Better to spend 2 hours thinking about the problem and designing a solution and 1 hour writing code than to spend 3 hours writing code.

This is especially true of a language like C++, where the design space language is very removed from the implementation space language. I think a more dynamic language like Python is better to start coding at an earlier stage. In C++, if only for the mere reason of static typing, you better do some initial thinking ahead of time.

And always strive to avoid code duplication. When you have code duplication you are doing something wrong.
 

McLovin

Legend
So sad, c++ is so dated.... It's all java now...

I had a good chuckle at this. Everyone knows the best programming language is VALGOL:

Code:
14 LIKE, Y$KNOW (I MEAN) START
%% IF
PI A =LIKE B1TCHEN AND
01 B =LIKE TUBULAR AND
9  C =LIKE GRODY**MAX
4K (FERSURE)**2
18 THEN
4I FOR I=LIKE 1 TO OH MAYBE 100
86 DO WAH + (DITTY**2)
9  BARF(I) =TOTALLY GROSS(OUT)
-17 SURE
1F LIKE BAG THIS PROGRAM
?  REALLY
$$ LIKE TOTALLY (Y*KNOW)
 

McMurphy

Banned
I had a good chuckle at this. Everyone knows the best programming language is VALGOL:

Code:
14 LIKE, Y$KNOW (I MEAN) START
%% IF
PI A =LIKE B1TCHEN AND
01 B =LIKE TUBULAR AND
9  C =LIKE GRODY**MAX
4K (FERSURE)**2
18 THEN
4I FOR I=LIKE 1 TO OH MAYBE 100
86 DO WAH + (DITTY**2)
9  BARF(I) =TOTALLY GROSS(OUT)
-17 SURE
1F LIKE BAG THIS PROGRAM
?  REALLY
$$ LIKE TOTALLY (Y*KNOW)


Brilliant! :)
 

McLovin

Legend
That was stolen from the old (and mean old) 'fortune' program from Sun OS (Actually, I believe it was from a book originally).

If you Google 'Lesser Known Programming Languages', you can see the full list.
 

McMurphy

Banned
That was stolen from the old (and mean old) 'fortune' program from Sun OS (Actually, I believe it was from a book originally).

If you Google 'Lesser Known Programming Languages', you can see the full list.

Thank you, sir. I definitely will check this out. :)
 
Top