Problem with code - Can someone take a look???

This is a discussion on Problem with code - Can someone take a look??? within the C++ Programming forums, part of the General Programming Boards category; Can someone tell me what's wrong with the following code. I am using Borland C++ and I am getting the ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    Problem with code - Can someone take a look???

    Can someone tell me what's wrong with the following code. I am using Borland C++ and I am getting the following error messages:

    Expression Syntax
    Statement Missing
    Declaration Syntax Error
    Declaration Missing

    I'm attaching the code. It's in .cpp form, so it cannot contain any viruses.
    Attached Files Attached Files

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    This:
    Code:
    if(Dice1=='1')&&(Dice2=='1')
    Should be this:
    Code:
    if ((Dice1=='1')&&(Dice2=='1'))
    
    gg

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Next time, try compiling more often - like before you copy/paste the same error 30-odd times through the rest of your code.

    And you SO need a better way of printing the dice
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    yeah, thanks

    I agree about the dice. I'm just a student, and I'm learning the language. This is a project, and I couldn't figure it out. The teacher told me to post here, for assistance. I haven't learned much into windows yet, still all dos, so that's the best I have got for the moment. Thanks for the help.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    Here is a simple example of how you can print die without having to "hardcode" every permutation.
    Code:
    #include <iostream>
    using namespace std;
    
    
    unsigned int validate_die(unsigned int val)
    {
        if (val < 1)
        {
            val = 1;
        }
        else if (val > 6)
        {
            val = 6;
        }
    
        // DIE array index starts at 0
        val--;
    
        return val;
    }//validate_die
    
    
    void print_die(unsigned int d1,unsigned int d2)
    {
        const char BORDER = '*';
        const char EDGE[] = "*********";
        const char DIE[6][3][8] = 
        {
            {
                "       ",
                "   o   ",
                "       ",
            },
            {
                "  o    ",
                "       ",          
                "    o  ",
            },
            {
                "  o    ",
                "   o   ",
                "    o  ",
            },
            {
                "  o o  ",
                "       ",
                "  o o  ",
            },
            {
                "  o o  ",
                "   o   ",
                "  o o  ",
            },
            {
                "  o o  ",
                "  o o  ",
                "  o o  ",
            },
        };
        const char LEADING_SPACE[] = "                             ";
        const char SEP_SPACE[] = "   ";
    
        d1 = validate_die(d1);
        d2 = validate_die(d2);
            
        // Top of die
        cout << LEADING_SPACE << EDGE << SEP_SPACE << EDGE << endl;
    
        // Insides
        for (int n = 0; n < 3; n++)
        {
            cout << LEADING_SPACE 
                 << BORDER << DIE[d1][n] << BORDER 
                 << SEP_SPACE 
                 << BORDER << DIE[d2][n] << BORDER 
                 << endl;
        }//for
    
        // Bottom of die
        cout << LEADING_SPACE << EDGE << SEP_SPACE << EDGE << endl;
        cout << endl;
    }//print_die
    
    
    int main()
    {
        print_die(1,6);
        print_die(5,3);
        print_die(2,4);
    
        return 0;
    }//main
    gg

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Uhh... A couple thoughts. The first being, you might want to work on some different formatting.

    This is hard to read:
    Code:
    else if((Dice1=='1')&&(Dice2=='2'))
    	{cout<<"                             *********   *********                               "<<endl;
    	cout<<"                             *       *   * o     *                               "<<endl;
    	cout<<"                             *   o   *   *       *                               "<<endl;
    	cout<<"                             *       *   *     o *                               "<<endl;
    	cout<<"                             *********   *********                               "<<endl;}
    This:
    Code:
    else if((Dice1=='1')&&(Dice2=='2')) {
    	cout<<"                             *********   *********                               "<<endl;
    	... etc ...
    }
    and this:
    Code:
    else if((Dice1=='1')&&(Dice2=='2'))
    {
    	cout<<"                             *********   *********                               "<<endl;
    	... etc ...
    }
    are much easier to read.

    Also, about printing these dice. You might want to make a function that takes a) the number on the dice, and b) the line to print, and then gives you a string which you then print.

    A brief example of what I mean:
    string getLine(int numberOnDice, int line);

    getLine(5, 1) returns "* o o *"
    getLine(5, 2) returns "* o *"
    etc...

    It'd be much nicer to work with.

    *edit
    Or codeplug's works too.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    another problem

    When I run the attached code, my menu comes up, but the dice program doesn't display any dice. For example, once it gets to the randomize part, it doesn't display the dice. It just closes. any ideas??? I really appreciate the assistance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21