I'm trying to run this for loop. I've included the entire code to try to solve the problem. I'm really not understanding why this is not looping. When I enter an invalid selection it should make the user input it again, but it's not looping. To re-create my problem when running choose a number greater then 5. The area's i'm questioning about are in red. Any input is apprechiated.
Code:
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
int main()
{
int selection, amount, count, prog;
double angle, angle2, angle3, radians, radians2, radians3, forcex, forcey, force, force2, totalx, totaly, value, resultant, direction, degree;
#define PI 3.141592654
printf("Welcome to the Cacluator of Statics of Materials.\n\n");
printf("1. 2-D resultant force at a point.\n");
printf("2. 2-D uknown force vectors with angles (Max 2) with known resultant force. \n");
printf("3. I'm not sure yet. \n");
printf("4. Directions. \n");
printf("5. Exit the program.\n\n");
prog = 0;
for(prog == 0;prog > 0; prog++);
{
printf("Please choose a selection: ");
scanf("%d", &selection);
if(selection == 1)
{
printf("\nYou choose to calcualte a resultan force at a point.\n\n");
printf("Please input the amount of Forces: ");
scanf("%d", &amount);
int forces[amount];
count = 0;
totalx = 0;
totaly = 0;
for(count = 0; count < amount; count++)
{
printf("\nPlease input the unit value of force #%d: ", count+1);
scanf("%lf", &value);
forces[count] = value;
printf("\nPlease input the positive angle from the x axis: ");
scanf("%lf", &angle);
radians = angle * PI / 180;
forcex = value * cos(radians);
forcey = value * sin(radians);
totalx = totalx + forcex;
totaly = totaly + forcey;
}
resultant = sqrt(totalx * totalx + totaly * totaly);
direction = atan(totaly/totalx);
degree = direction * 180 / PI;
printf("\nThe unit value of the forces in the x direction is: %8.4lf \n", totalx);
printf("The unit value of the forces in the y direction is: %8.4lf \n", totaly);
printf("The resultant force is: %8.4lf units at %8.4lf degrees.\n\n", resultant, degree);
}
else if(selection == 2)
{
printf("\nYou choose to caclulate two unkown vectors.\n\n");
printf("Please input the magnitude of the resultant force: ");
scanf("%lf", &resultant);
printf("Please input the angle of the first unknown from the resultant force: ");
scanf("%lf", &angle);
if(angle < 0)
{
angle = angle * -1;
}
else
{
printf("Please input the angle of the second unkown form resultant force: ");
scanf("%lf", &angle2);
}
if(angle2 < 0)
{
angle2 = angle2 * -1;
}
else
{
radians = angle * PI / 180;
radians2 = angle2 * PI / 180;
angle3 = 180 - (angle + angle2);
radians3 = angle3 * PI / 180;
force = resultant/sin(radians3)*sin(radians2);
force2 = resultant/sin(radians3)*sin(radians);
printf("\nThe first unknown is: %8.4lf units.", force);
printf("\nThe second unknown is: %8.4lf units.\n\n", force2);
}
}
else if(selection == 3)
{
}
else if(selection == 4)
{
printf("\nPlease read the following instructions for proper operations:\n\n");
}
else if(selection == 5)
{
printf("\nExiting the program.\n\n");
prog = -2;
}
else
{
printf("\nSelection Invalid! Please re-enter your selection.\n\n");
prog = 0;
}
}
system("PAUSE");
}