Thread: Doh!

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    Doh!

    Ok I use the following function but i get strange errors..

    Code:
    double term(bool get)				// multiply and divide
    {
          double left = prim(get);
          
          for (;;)
    	  switch (curr_tok)
    	  {
    	        case POWER :
    		    double y = prim(true); //error is here!
    		    power(y,left);
    		    break;
    	        case MUL :
    		    left *= prim(true);
    		    break;
    	        case DIV :
    		    if (double d = prim(true))
    		    {
    			left /= d;
    			break;
    		    }
    		    return error("Divide by 0");
    	        default :
    		    return left;
    	  }
    }
    I get the following errors/warning..

    /Users/luigi/Documents/c++/Bjarne/Project Builder/Ch 6/ex18*/calc.cpp:122: crosses initialization of `double y'
    /Users/luigi/Documents/c++/Bjarne/Project Builder/Ch 6/ex18*/calc.cpp:125: warning: jump to case label

    case Div is about the same but I dont get any errors... why is that so?
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What is prim( ) defined as?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    well here is the full code..
    but dont use create() function its not working yet..
    and im trying to fix power as asked in this post..
    but dont worry nothing dangerous..
    everything else should work perfectly..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Compiles with a completely different error for me:

    g:\c++\luigicalc\calc.cpp(205) : error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

    But the part that's giving you trouble seems to be fine.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    where do you get that error and with wich compiler?
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Sorry, I forgot to mention that I'm using MSVC++ 6.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    I finally decided to try it on code warrior 8.3 and i got no errors at all..
    and now everything is going great...

    I guess pb needs to be upgraded..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doh array inversion
    By curlious in forum C++ Programming
    Replies: 1
    Last Post: 01-04-2004, 01:54 AM
  2. d'oh
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 05-18-2002, 03:47 PM
  3. Tic Tac DOH!
    By Invincible in forum C++ Programming
    Replies: 14
    Last Post: 04-23-2002, 03:38 PM
  4. Can someone tell my why this is...
    By Sinamerica in forum C++ Programming
    Replies: 2
    Last Post: 03-04-2002, 03:20 AM
  5. I need some help for my game
    By valar_king in forum Game Programming
    Replies: 0
    Last Post: 12-27-2001, 11:35 AM