new to C++/this forum hi!

hi
so im new to c++ and am trying to change a number;

int hep=0;

switch(hep)
{
case 0:
if ( item.name=="barrel")
{
AddMessage(S+"111111");

int hep= ++hep;//this part gives me trouble
//hep =versy;
}
case 1:
if ( item.name=="barrel2")
{
AddMessage(S+"22222");
}

right now it works where the BOTH cases show when item names are touched (this is for a game im using essenthial engine) and I want the first case to be no longer recognized, ie if case 1 is true case 0 is no longer 0. I thnk it hs to do with how Im adding I thought hep++ may do it but Im stuck! thanks in advance!

closed account (SECMoG1T)
int hep= ++hep;//this part gives me trouble
You are redifing hep so there is a name conflict with the previous hep

Use ++hep alone its good to get the whole thing done

Plus you might consider breaking from your cases to avoid all the cases being executed
Insert break; before every new case (case 0: is okay, but before case 1 it's got to have a break;.
use code tags.
1
2
3
4
5
6
7
if ( item.name=="barrel")
{
AddMessage(S+"111111");

int hep= ++hep;//this part gives me trouble
//hep =versy;
}


In the above code you are creating a new variable named hep in the scope of the if statement, not using the previous variable named hep. All you should need is ++hep;.

thank you.
ok i have this now..not sure if c++ needs {} for the ifs there...but its actually reading 0,then 1 then sometimesgoesback to 0- cant get it to two ...yet.. o k thanks

int hep=0;


switch(hep)
{

case 0:
if ( item.name=="barrel")

++hep;
AddMessage(S+"111111er"+ hep);

// int hep= ++hep;
//hep =versy;



//if item name ==?? new cas
break;
case 1:
if ( item.name=="biggun")

++hep;
AddMessage(S+"22222er"+ hep);


break;
case 2:
if ( item.name=="Spirit")

++hep;
AddMessage(S+"333333er"+hep);


break;
}
Topic archived. No new replies allowed.