ppplayer80
October 29th, 2013, 05:26 PM
Hi,
I'm sorry if this problem was already discussed here. I don't know what to type in Google to find it.
Here is a fragment of my code:
if (var/900==1 || var/400==1)
{
var2[i] = 'C';
i++;
if (var/900==1)
{
var2[i] = 'M';
var = var - 900;
}
else
{
var2[i] = 'D';
var = var - 400;
}
i++;
}
And I think I know why this generates problem. Parser think that "else" instruction refers to the first if, but it doesn't. As a result, if my 'var' variable doesn't match the first condition, it goes to the ' var2[i] = 'D' ' line and breaks whole program (because it should completely leave this fragment of code if it doesn't match the first condition).
I'm a new Linux user and I use Terminal's 'gcc' command to compile my programs. I also use c99 standard.
Can you please help me?
EDIT//
Problem was in an int conversion (for example 700/400 = 1)
I'm sorry if this problem was already discussed here. I don't know what to type in Google to find it.
Here is a fragment of my code:
if (var/900==1 || var/400==1)
{
var2[i] = 'C';
i++;
if (var/900==1)
{
var2[i] = 'M';
var = var - 900;
}
else
{
var2[i] = 'D';
var = var - 400;
}
i++;
}
And I think I know why this generates problem. Parser think that "else" instruction refers to the first if, but it doesn't. As a result, if my 'var' variable doesn't match the first condition, it goes to the ' var2[i] = 'D' ' line and breaks whole program (because it should completely leave this fragment of code if it doesn't match the first condition).
I'm a new Linux user and I use Terminal's 'gcc' command to compile my programs. I also use c99 standard.
Can you please help me?
EDIT//
Problem was in an int conversion (for example 700/400 = 1)