Random 无法退出循环,请成功运行程序
我正在为C编写一个编程任务,程序运行了,但它似乎没有执行循环。该程序的目的是使用随机数生成器获取变量,使用switch语句确定气球的体积,然后计算填充池需要多少气球。然而,当我运行它的时候,它只是坐在那里,好像它在等待输入,或者它不能退出循环。程序应该以批处理模式运行。任何帮助都将不胜感激!谢谢Random 无法退出循环,请成功运行程序,random,while-loop,switch-statement,Random,While Loop,Switch Statement,我正在为C编写一个编程任务,程序运行了,但它似乎没有执行循环。该程序的目的是使用随机数生成器获取变量,使用switch语句确定气球的体积,然后计算填充池需要多少气球。然而,当我运行它的时候,它只是坐在那里,好像它在等待输入,或者它不能退出循环。程序应该以批处理模式运行。任何帮助都将不胜感激!谢谢 #include <stdio.h> #include <math.h> #include <stdlib.h> #inclu
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define Gravity 32 //feet per second^2 and gravitational accelleration
#define PI 3.14159
#define BAL_HEIGHT 12 //balcony height in feet
#define POOL_CENTER 35 //distance to the center of the pool in feet
#define thetaMin 5 //degrees
#define thetaMax 85 //degrees
#define velocityMin 1 //foot per second
#define velocityMax 30 //feet per second
#define heightMin 4.5 //feet
#define heightMax 7.0 //feet
#define minDiameter 3 //inches
#define maxDiameter 9 //inches
#define Capacity 7 // pool capacity in gallons
int main ()
{
//inputs theta, velocity, height, diameter, balloons, volume, and capacity
//in degrees
//in feet per second
//of the thrower //for rand max/min
double currentCapacity = 0; //set beginning capacity to zero
double volume;
double volumeTotal = 0;
int diameter;
int balloonsThrown = 0;
int balloonsHit = 0; //set beginning balloons thrown and hit to zero
srand(time(NULL)); //seed sit using time
while (volumeTotal <= Capacity)
{
double theta = (double) rand()/RAND_MAX * (thetaMax - thetaMin +1) + thetaMin;
double velocity = (double) rand()/RAND_MAX * (velocityMin - velocityMax +1) + velocityMin;
double height = (double) rand()/RAND_MAX * (heightMin - heightMax +1) + heightMin;
int diameter = rand() % (maxDiameter - minDiameter + 1) + minDiameter;
int balloonsThrown = rand() % (RAND_MAX);
switch (diameter) // get diameter from rand equation
{
case 3:
volume == 0.1;//gallons
break;
case 4:
volume == 0.2;
break;
case 5:
volume == 0.3;
break;
case 6:
volume == 0.55;
break;
case 7:
volume == 0.8;
break;
case 8:
volume == 1.25;
break;
case 9:
volume == 1.7;
break;
}
// compute distance
double LAUNCH_HEIGHT = BAL_HEIGHT + height; //the sum of the input height and the balcony height
double radians = theta*(PI/180); //convert angle theta into radians
double part1 = (velocity*(cos(radians))/Gravity); //first part of the velocity equation
double part2 = velocity*(sin(radians)); //second part of velocity equation
double part3 = pow(velocity*(sin(radians)),2);//exponential part of the velocity equation
double part4 = 2*(Gravity*LAUNCH_HEIGHT);
double distance = part1*(part2 + sqrt(part3+part4)); //full distance function
//determine whether or not the balloon will fill the pool
//increment the amount of balloons thrown and that hit the pool
if (distance <= POOL_CENTER -1 && POOL_CENTER +1 >= distance);
{ // distance is in the range of 34-36 (Pool Center +- 1)
(currentCapacity += volumeTotal);
}
if (distance > 0);
{
(balloonsThrown ++);
}
//determining whether to add the balloon to the hit total
if (distance > POOL_CENTER -1 && distance < POOL_CENTER +1)
{
(balloonsHit ++);
}
}
double balloonPercentage = (balloonsHit/balloonsThrown);
printf ("%d balloons hit the pool.\n", balloonsHit);
printf ("%d balloons were thrown\n", balloonsThrown);
printf ("%2f%% of balloons hit the pool\n", balloonPercentage);
return 0;
}
#包括
#包括
#包括
#包括
#定义重力每秒32//ft^2和重力加速度
#定义PI 3.14159
#定义阳台高度12//阳台高度(英尺)
#定义游泳池\u中心35//到游泳池中心的距离(英尺)
#定义5//度的平面
#定义最大值85//度
#定义速度单位为每秒1//ft
#定义速度最大为每秒30//ft
#定义最小高度4.5//英尺
#定义最大高度7.0//英尺
#定义minDiameter 3//英寸
#定义最大直径9//in
#定义容量7//池容量(加仑)
int main()
{
//输入θ、速度、高度、直径、气球、体积和容量
//度
//以英尺每秒为单位
//投掷者的最大/最小兰特
double currentCapacity=0;//将起始容量设置为零
双卷;
双体积总和=0;
内径;
int ballodesthrown=0;
int ballodshit=0;//将抛出并命中的起始气球设置为零
srand(time(NULL));//种子使用时间
而(体积总和0);
{
(balloosthrown++);
}
//确定是否将气球添加到命中总数
如果(距离>泳池中心-1和距离<泳池中心+1)
{
(b++);
}
}
双气球百分比=(气球屎/气球重量);
printf(“%d个气球击中池。\n”,balloodshit);
printf(“%d个引出序号被抛出\n”,ballodesthrown);
printf(“%2f%%个气球击中池\n”,气球百分比);
返回0;
}
while(volumeTotalwhile(volumeTotal
while (volumeTotal <= Capacity)