S
Scott
Hi,
Now this one does not make any sense to me at all. I have a while
loop and it is not working anything like it is suppose to. I have
placed it below.
-------------------------
Count = 1;
while(count < 4)
{
if(count == 1) rating2 = security;
if(count == 2) rating2 = health;
if(count == 3) rating2 = security;
bonus = (rating2 / 10) - 5;
bonus2 = 10 * (rating2 - ((bonus + 5) * 10));
if (bonus2 < 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((unsigned) time(NULL));
roll = rand()/(int)(((unsigned)RAND_MAX + 1) / 100);
if (bonus2 >= roll) bonus++;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
loop = loop - 1;
printf("feconomy: %i\n", feconomy);
printf("fhealth: %i\n", fhealth);
if (count >= 2)
{
bonus = (rating2 / 10) - 5;
bonus2 = 10 * (rating2 - ((bonus + 5) * 10));
if (bonus2 < 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((unsigned) time(NULL));
roll = rand()/(int)(((unsigned)RAND_MAX + 1) / 100);
if (bonus2 >= roll) bonus++;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
}
count = count + 1;
}
-----------------------------
First, the while loop exits before reaching 3 even though I have the
while going until count is less than 4. Then, if I try and put less
than 5, something even more weird happens, it somehow goes into a
endless loop even though I have one being added in each loop.
Second, the program seems to go along as if the if with brackets does
not exsist. It simply does the code in the brackets every time, even
if the count is equal to 1.
I have spent a few hours now trying to fix this and I can't see what I
am doing wrong. I have used several ifs and whiles in my program
without any trouble.
--
Your friend,
Scott
Sent to you from a 100% Linux computer using Kubuntu Version 7.04
(Feisty Fawn)
Now this one does not make any sense to me at all. I have a while
loop and it is not working anything like it is suppose to. I have
placed it below.
-------------------------
Count = 1;
while(count < 4)
{
if(count == 1) rating2 = security;
if(count == 2) rating2 = health;
if(count == 3) rating2 = security;
bonus = (rating2 / 10) - 5;
bonus2 = 10 * (rating2 - ((bonus + 5) * 10));
if (bonus2 < 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((unsigned) time(NULL));
roll = rand()/(int)(((unsigned)RAND_MAX + 1) / 100);
if (bonus2 >= roll) bonus++;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
loop = loop - 1;
printf("feconomy: %i\n", feconomy);
printf("fhealth: %i\n", fhealth);
if (count >= 2)
{
bonus = (rating2 / 10) - 5;
bonus2 = 10 * (rating2 - ((bonus + 5) * 10));
if (bonus2 < 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((unsigned) time(NULL));
roll = rand()/(int)(((unsigned)RAND_MAX + 1) / 100);
if (bonus2 >= roll) bonus++;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
}
count = count + 1;
}
-----------------------------
First, the while loop exits before reaching 3 even though I have the
while going until count is less than 4. Then, if I try and put less
than 5, something even more weird happens, it somehow goes into a
endless loop even though I have one being added in each loop.
Second, the program seems to go along as if the if with brackets does
not exsist. It simply does the code in the brackets every time, even
if the count is equal to 1.
I have spent a few hours now trying to fix this and I can't see what I
am doing wrong. I have used several ifs and whiles in my program
without any trouble.
--
Your friend,
Scott
Sent to you from a 100% Linux computer using Kubuntu Version 7.04
(Feisty Fawn)