奇怪的同时和如果 [英] The weird while and If
问题描述
现在这个根本没有任何意义。我有一段时间
循环,它没有像它想象的那样工作。我将
放在下面。
------------------------ -
计数= 1;
而(计数<4)
{
如果(count == 1)rating2 = security;
if(count == 2)rating2 = health;
if(count == 3)rating2 = security;
bonus =(rating2 / 10) - 5;
bonus2 = 10 *(rating2 - ((奖励+5)* 10));
if(bonus2< 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((无符号)时间(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(经济:%i \ n,经济);
printf(fhealth:%i \ n,fhealth);
if(count> ; = 2)
{
bonus =(rating2 / 10) - 5;
bonus2 = 10 *(rating2 - ((奖励+) 5)* 10));
if(bonus2< 0)
{
奖金 - ;
bonus2 = bonus2 + 100;
}
srand((无符号)时间(NULL));
roll = rand()/(int)(((unsigned)RAND_MAX + 1)/ 100);
if(bonus2> = roll)bonus ++;
if(count = 1)fhealth = fhealth + bonus;
if(count = 2)feconomy = feconomy +奖金;
if(count = 3)feconomy = feconomy + bonus;
}
count = count + 1;
}
-----------------------------
首先,while循环在达到3之前退出,即使我有
,直到count小于4.然后,如果我尝试减去
比5,更奇怪的事情发生了,它以某种方式进入了一个无限循环,即使我在每个循环中都添加了一个。
其次,这个程序好像是带括号的if一样,而不是
不是exsist。它只是每次都在括号中的代码,如果计数等于1,甚至是
。
我现在花了几个小时试图修复这个,我看不出我做错了什么。我在我的程序中使用了几个ifs和whiles
没有任何问题。
-
你的朋友,>
Scott
使用Kubuntu 7.04版从100%Linux电脑发送给你
(Feisty Fawn)
>
推荐答案
4月1日晚上8:51,Scott < scle ... @ gmail.comwrote:
On Apr 1, 8:51 pm, "Scott" <scle...@gmail.comwrote:
现在这个没有任何意义我。我有一段时间
循环,它没有像它想象的那样工作。我将
放在下面。
------------------------ -
计数= 1;
而(计数<4)
{
如果(count == 1)rating2 = security;
if(count == 2)rating2 = health;
if(count == 3)rating2 = security;
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;
[...]
[...]
if(count = 1)fhealth = fhealth + bonus; <如果(计数= 2)经济=经济+奖金;
如果(计数= 3)经济=经济+奖金;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
[...]
[...]
if(count = 1)fhealth = fhealth + bonus; <如果(计数= 2)经济=经济+奖金;
如果(计数= 3)经济=经济+奖金;
if (count = 1) fhealth = fhealth + bonus;
if (count = 2) feconomy = feconomy + bonus;
if (count = 3) feconomy = feconomy + bonus;
你在第一组if条件中看到了什么不同,
当你把它们与第二组和第三组进行比较时? :)
Do you see anything different in the first group of if conditions,
when you compare them to the second and third? :)
Count = 1;
[snip]
Count = 1;
[snip]
if(count> = 2)
if (count >= 2)
标识符区分大小写。如果您复制并粘贴了代码,请尝试
修复该代码。
Identifiers are case sensitive. If you copied and pasted the code, try
fixing that.
4月1日,21:51,Scott < scle ... @ gmail.comwrote:
On 1 Apr, 21:51, "Scott" <scle...@gmail.comwrote:
现在这个没有任何意义我。我有一段时间
循环,它没有像它想象的那样工作。我将
放在下面。
------------------------ -
计数= 1;
而(计数<4)
{
如果(count == 1)rating2 = security;
if(count == 2)rating2 = health;
if(count == 3)rating2 = security;
bonus =(rating2 / 10) - 5;
bonus2 = 10 *(rating2 - ((奖励+5)* 10));
if(bonus2< 0)
{
bonus--;
bonus2 = bonus2 + 100;
}
srand((无符号)时间(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 + bo新加坡国立大学;
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;
在上面的3行中你有作业而不是比较。
我建议你开始使用像spint这样的代码检查工具;它将会收起这样的愚蠢错误。
In the 3 lines above you have assignment instead of comparison.
I suggest you start using a code checking tool like spint ; it will
pick up silly mistakes like that.
这篇关于奇怪的同时和如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!