I have written a displayResults function where I pass through all of my calculations into the arguments and print each line.
The console application stays open each time it is asking for data, but as soon as it gets to the displayResults function the window closes.
I have already included the system("Pause); hoping it would keep the window open but it did not work.
The function I am referring to:
void displayResults(double force, double volume, char encodeTxt, double distance,
double tangent, double resist, double y)
{
printf("The force = %lf\n", force);
printf("The volume = %lf\n", volume);
printf("The encoded character = %c", encodeTxt);
printf("The distance = %lf", distance);
printf("The tangent = %lf", tangent);
printf("The resistance = %lf", resist);
printf("The y value = %lf", y);
system("Pause");
}
Here is more of my code:
double getForce(void)
{
double force = 0, mass = 0, accel = 0;
printf("Enter the mass:\n");
scanf("%lf", &mass);
printf("Enter the acceleration:\n");
scanf("%lf", &accel);
force = mass * accel;
return force;
}
double getVolume(void)
{
double volume = 0, radius = 0, height = 0;
printf("Enter radius of cylinder:\n");
scanf("%lf", &radius);
printf("Enter height of cylinder:\n");
scanf("%lf", &height);
volume = PI * pow(radius, 2) * height;
return volume;
}
char getEncode(void)
{
char encodeTxt, plainTxt;
int shift = 0;
printf("Enter a character:\n");
scanf(" %c", &plainTxt);
printf("Enter an integer");
scanf("%d", &shift);
encodeTxt = (plainTxt - 'A') + 'a' - shift;
return encodeTxt;
}
double getDistance(void)
{
double distance = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0;
printf("Enter first point:\n");
scanf("%lf%lf", &x1, &y1);
printf("Enter second point:\n");
scanf("%lf%lf", &x2, &y2);
distance = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
return distance;
}
double getTangent(void)
{
double tangent = 0, theta = 0;
printf("Enter the theta angle:\n");
scanf("%lf", &theta);
tangent = sin(theta) / cos(theta);
return tangent;
}
double getResist(void)
{
double resist = 0;
int r1 = 0, r2 = 0, r3 = 0;
printf("Enter three resistors:\n");
scanf("%d%d%d", &r1, &r2, &r3);
resist = 1 / (1 / r1 + 1 / r2 + 1 / r3);
return resist;
}
double equation(void)
{
double x = 0, y = 0, z = 0;
int a = 0;
printf("Enter the a value:\n");
scanf("%d", &a);
printf("Enter the x, y, z values:\n");
scanf("%lf%lf%lf", &x, &y, &z);
y = ((double)2 / (double)3) - y + z * x / (a % 2) + PI;
return y;
}
And lastly my main function:
int main(void)
{
double force = 0, volume = 0, distance = 0,
tangent = 0, resist = 0, y = 0;
char encodeTxt;
force = getForce();
volume = getVolume();
encodeTxt = getEncode();
distance = getDistance();
tangent = getTangent();
resist = getResist();
y = equation();
displayResults(force, volume, encodeTxt, distance, tangent, resist, y);
return 0;
}
I expect the console to display my results but after asking for the last x, y z values from my equation function, it ceases to work.