if function error menu

User Tag List

Results 1 to 6 of 6
  1. #1
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if function error

    Ì started reading in a book about c++ today and it seems quite interesting so I tried to make a simple calculator however the compiler is complaining about my code i get the following errors on the code below

    1>.\mini.cpp(11) : error C2059: syntax error : ')'
    1>.\mini.cpp(15) : error C2059: syntax error : ')'
    1>.\mini.cpp(19) : error C2059: syntax error : '/'
    1>.\mini.cpp(23) : error C2059: syntax error : ')'

    Code:
                             if (TS = +);
    		{
    		    Resultat = Första + Andra;
    		}
    		if (TS = -);
    		{
    			Resultat = Första - Andra;
    		}
    		if (TS = / );
    		{
    			Resultat = Första / Andra;
    		}
    		if (TS = *);
    		{
    			Resultat = Första * Andra;
    		}
    any help is appreciated

    note: not the whole code just the part i'm getting error from

    if function error
  2. #2
    lolfire's Avatar Member
    Reputation
    -4
    Join Date
    Aug 2009
    Posts
    70
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
                             if (TS == +)
    		{
    		    Resultat = Första + Andra;
    		}
    		if (TS == -)
    		{
    			Resultat = Första - Andra;
    		}
    		if (TS == / )
    		{
    			Resultat = Första / Andra;
    		}
    		if (TS == *)
    		{
    			Resultat = Första * Andra;
    		}
    You forgot some == in in the if's. You had ; after if() which is wrong.

    I'm not sure if you can use åäö as variables and I think else if instead of just bunch of ifs.


    NOTE: Could be wrong though, only worked with C++ for 2 days.

    You could also do them as switches:

    Code:
    switch (TS)
    {
        case -:
        Resultat = Forsta - Andra;
        break;
    
        case +:
        Resultat = Forsta + Andra;
        break;
    
        case /:
        Resultat = Forsta / Andra;
        break;
    
        case *:
        Resultat = Forsta * Andra;
        break;
    }
    Last edited by lolfire; 01-28-2010 at 04:15 PM.

  3. #3
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah i see so cases don't require == or '+' ?

  4. #4
    lolfire's Avatar Member
    Reputation
    -4
    Join Date
    Aug 2009
    Posts
    70
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lolicon123 View Post
    ah i see so cases don't require == or '+' ?
    Code:
    switch (TS)
    {
        case -:
        Resultat = Forsta - Andra;
        break;
    Is basically

    Code:
    if(TS == -)
    {
        Resultat = Forsta - Andra;
    }
    It's better when using many conditions.

  5. #5
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try creating actual strings, and not just typing the character you're looking for. The compiler is stupid. It only does what you tell it to.

  6. #6
    Dal's Avatar Member
    Reputation
    8
    Join Date
    Jun 2007
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to make sure its perfectly clear since I can see you possibly not understanding what they're saying.

    This is what you have after the first response:

    Code:
            if (TS = +)
    		{
    		    Resultat = Första + Andra;
    		}
    		if (TS = -)
    		{
    			Resultat = Första - Andra;
    		}
    		if (TS = / )
    		{
    			Resultat = Första / Andra;
    		}
    		if (TS = *)
    		{
    			Resultat = Första * Andra;
    		}
    This is what it should be:

    Code:
            if (TS == "+")
    		{
    		    Resultat = Första + Andra;
    		}
            if (TS == "-")
    		{
    			Resultat = Första - Andra;
    		}
            if (TS == "/" )
    		{
    			Resultat = Första / Andra;
    		}
            if (TS == "*")
    		{
    			Resultat = Första * Andra;
    		}
    First off as the first reply mentioned, to compare values in the manner you have above you use ==. This is because just using the = sign is the operator for assignment within the compiler.

    Secondly, what you intend to do is compare string values (or perhaps chars, but I doubt it =) ). For Strings, you have to use double quotes around them. This is how the compiler knows that its using a string.

    Also as a bonus tip. If you have just one line after an if or for statement, you do not need to have brackets around the code. For example, you can also write this as.

    Code:
            if (TS == "+")
    		    Resultat = Första + Andra;
            if (TS == "-")
    	               Resultat = Första - Andra;
            if (TS == "/" )
    		    Resultat = Första / Andra;
            if (TS == "*")
    		    Resultat = Första * Andra;
    Good Luck.

Similar Threads

  1. "pure virtual function call" c++ error
    By Kzuly in forum Diablo 3 Emulator Servers
    Replies: 2
    Last Post: 10-21-2011, 12:37 AM
  2. Error Adding Easy Functions [C++]
    By mager1794 in forum WoW EMU Questions & Requests
    Replies: 1
    Last Post: 08-22-2008, 09:48 AM
  3. WoW Emu error
    By bezike in forum World of Warcraft General
    Replies: 1
    Last Post: 06-28-2006, 03:18 PM
  4. Site Error?
    By Amedis in forum Community Chat
    Replies: 8
    Last Post: 06-21-2006, 08:31 AM
  5. Error in checking WoW.exe CRC code hack?
    By Trichelieu in forum World of Warcraft General
    Replies: 0
    Last Post: 06-11-2006, 02:24 PM
All times are GMT -5. The time now is 05:02 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search