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

Discussion in 'Odds & Ends' started by Maximagq, Aug 20, 2014.

  1. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    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: Aug 20, 2014
    #1
  2. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    Sorry just noticed that copy and paste removes all the spacing and makes it almost informattable. Apologies :(
     
    #2
  3. kOaMaster

    kOaMaster Hall of Fame

    Joined:
    Jun 10, 2009
    Messages:
    3,026
    Location:
    Basel/Switzerland
    could you post this within a "code"-block?
     
    #3
  4. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    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);
    }
     
    #4
  5. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    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.
     
    #5
  6. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    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 :(
     
    #6
  7. kOaMaster

    kOaMaster Hall of Fame

    Joined:
    Jun 10, 2009
    Messages:
    3,026
    Location:
    Basel/Switzerland
    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: Aug 20, 2014
    #7
  8. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    Hm so I should use a switch statement to use the keyword 'case'?
     
    #8
  9. kOaMaster

    kOaMaster Hall of Fame

    Joined:
    Jun 10, 2009
    Messages:
    3,026
    Location:
    Basel/Switzerland
    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: Aug 20, 2014
    #9
  10. sureshs

    sureshs Bionic Poster

    Joined:
    Oct 1, 2005
    Messages:
    35,099
    If an argument doesn't change inside a function, declare it const for clarity and enforcement.
     
    #10
  11. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    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);
    }
     
    #11
  12. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    How can I share .exe files with you guys? I have it on my Desktop.
     
    #12
  13. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    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: Aug 20, 2014
    #13
  14. bullfan

    bullfan Legend

    Joined:
    Sep 19, 2011
    Messages:
    7,805
    So sad, c++ is so dated.... It's all java now...
     
    #14
  15. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    There are good reasons for it.
     
    #15
  16. kOaMaster

    kOaMaster Hall of Fame

    Joined:
    Jun 10, 2009
    Messages:
    3,026
    Location:
    Basel/Switzerland
    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: Aug 26, 2014
    #16
  17. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    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.
     
    #17
  18. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    Upload the source to github with compilation/install instructions.



    Or upload to the App Store. (hehehe).

    Why not make an iOS app ?:)
     
    #18
  19. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    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.
     
    #19
  20. idono1301

    idono1301 Semi-Pro

    Joined:
    Mar 31, 2007
    Messages:
    408
    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 :)
     
    #20
  21. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    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 ?




    ..
     
    #21
  22. The Green Mile

    The Green Mile Legend

    Joined:
    Mar 2, 2014
    Messages:
    8,809
    Location:
    New Zealand
    I'll quote it so Chico can see....ANSWER HIM!
     
    #22
  23. Mr.Lob

    Mr.Lob Hall of Fame

    Joined:
    Aug 12, 2013
    Messages:
    2,506
    Location:
    Parts Unknown
    You insulted the man's favorite chocolate bar. Not cool Senti.
     
    #23
  24. The Green Mile

    The Green Mile Legend

    Joined:
    Mar 2, 2014
    Messages:
    8,809
    Location:
    New Zealand
    :lol::lol::lol::lol:
     
    #24
  25. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    "The code never bothered me anyway. Let it go"
     
    #25
  26. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    No, he insulted and made fun of my whole nation in a quite xenophobic several comments. Not cool at all, indeed.
     
    #26
  27. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    I suggest you read this - Dealing with Failure in Actor Systems:

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

    sureshs Bionic Poster

    Joined:
    Oct 1, 2005
    Messages:
    35,099
    senti suffers from premature optimization
     
    #28
  29. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    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.
     
    #29
  30. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    I love Orange Intense, too.

    Even more so now that it reminds me of my good friend, Chico.
     
    #30
  31. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    You mean i leak (memory) all over the place ?



    ..
     
    #31
  32. Chico

    Chico Banned

    Joined:
    Jun 29, 2013
    Messages:
    9,197
    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.
     
    #32
  33. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    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.
     
    #33
  34. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    This gentleman didn't have a good day when he poasted this, apparently. :mad:
     
    #34
  35. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    On the other hand, he really put that insufferable snob (and unrepentant superjerk) Sentinel in his right place. ;)
     
    #35
  36. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    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
     
    #36
  37. Underhand

    Underhand Legend

    Joined:
    Oct 17, 2008
    Messages:
    6,212
    Location:
    Serve'n Valley
    Who sentinels The Sentinel?
     
    #37
  38. movdqa

    movdqa Legend

    Joined:
    Sep 19, 2006
    Messages:
    8,488
    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.
     
    #38
  39. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    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.
     
    #39
  40. Maximagq

    Maximagq Banned

    Joined:
    Sep 17, 2013
    Messages:
    6,554
    Oh I wrote this in like 2 hours so that's why it looks like crap haha. Thanks for the comments.
     
    #40
  41. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    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.
     
    #41
  42. Sentinel

    Sentinel Bionic Poster

    Joined:
    Jan 21, 2008
    Messages:
    30,475
    Location:
    La Belle Époque
    I believe a semaphore does that.
     
    #42
  43. McLovin

    McLovin Hall of Fame

    Joined:
    Jun 2, 2007
    Messages:
    3,191
    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)
     
    #43
  44. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    :)

    C.A.R. Hoare doesn't have enough cycles to sentinel The Sentinel.
     
    #44
  45. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28

    Brilliant! :)
     
    #45
  46. McLovin

    McLovin Hall of Fame

    Joined:
    Jun 2, 2007
    Messages:
    3,191
    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.
     
    #46
  47. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    Thank you, sir. I definitely will check this out. :)
     
    #47
  48. Vcore89

    Vcore89 Hall of Fame

    Joined:
    Aug 27, 2012
    Messages:
    1,902
    Location:
    The synapse
    Cycles can be PURGEd, you need to LOOPed it until the system crashes.:)
     
    #48
  49. McMurphy

    McMurphy Banned

    Joined:
    Jan 20, 2015
    Messages:
    28
    My first laptop (a Toshiba Tecra 8100 that ran hot) has kept me many a night from dying of exposure thanks to the fine art of endless looping, gokd sir. ;)
     
    #49
  50. mikeler

    mikeler G.O.A.T.

    Joined:
    Sep 26, 2008
    Messages:
    19,698
    Location:
    Central Florida
    Anyone out there still using Fortran 77?
     
    #50

Share This Page