Hello all and thanks for taking a look at my problem. When I run this code, a few errors happen. Once the program reaches the Gauss Lens formula, it ignores all of the scanf()'s and returns values of 0's for my answer. Also, under 'character encoding' all I'm getting in return is 'a' regardless of what character I use as my &plaintext_character. The weird thing about the gauss lens formula is that if I play around with the formula, for example, letting focal_length = object_distance, it will not skip scanf(), but will skip with any other combination..here's my code:
Code:
#include<stdio.h>
#include<math.h>
#define _CRT_SECURE_NO_WARNINGS
#define PI 3.14159
int main(void)
{
float mass = 0, acceleration = 0, force = 0, radius = 0, height = 0, volume = 0, radius_squared = 0, object_distance = 0, image_distance = 0, focal_length = 0, tangent = 0, theta = 0;
char plaintext_character = 0, encoded_character;
printf("\t\t\t\t\tPhysics Calculator!\n\n");
//Newton's Second Law of Motion
printf("Newton's second law of motion: Force = Mass * Acceleration
\n\n");
printf("Find 'Mass' in kg and 'Acceleration' in m/s^2:\n");
printf("Mass = ");
scanf("%f", &mass);
printf("Acceleration = ");
scanf("%f", &acceleration);
force = mass * acceleration;
printf("Force = %.3f N\n", force);
//Volume
printf("\n\nFind the Volume of a cylinder with the following equation:
Volume = pi * r^2 * height. Find values in feet\n");
printf("Radius = ");
scanf("%f", &radius);
printf("Height = ");
scanf("%f", &height);
radius_squared = pow(radius, 2);
volume = radius_squared * height * PI;
printf("Volume = %.3lf ft^3", volume);
//character encoding
printf("\n\n\nEncoded_character = (plaintext_character - 'a') + 'A' \n");
printf("Enter a single character = ");
scanf("%f", &plaintext_character);
encoded_character = ( plaintext_character - 'a' ) + 'A';
printf("\nEncoded character = %c\n", encoded_character );
//Gauss Lens
printf("\n\nFind the focal length of a lens via the Gauss Lens
Formula : 1/f = 1/v + 1/u where v is the image distance and u is the object distance:\n\n");
printf("U = ");
scanf(" %f", &object_distance);
printf("\nV = ");
scanf(" %f", &image_distance);
focal_length = 1/(image_distance/1 + object_distance/1);
printf("\nFocal Length = %.3lf\n\n\n", focal_length);
//Tangent
printf("Find the Tangent of an angle in radians.\n");
printf("Enter an angle in radians: ");
scanf(" %f ", &theta);
tangent = sin(theta) / cos(theta);
printf("\nTangent%f = %lf\n", theta, tangent);
}