Can anyone help with my C language homework (Virsual Studio)? Almost done, need
ID: 668815 • Letter: C
Question
Can anyone help with my C language homework (Virsual Studio)? Almost done, need your corrections
3. Character encoding: encoded_character = (plaintext_character - 'A') + 'a' + shift; shift is an integer (note: what happens if plaintext_character is uppercase? What happens with various shift keys?)
6. Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3), for 3 resistors. R1, R2, and R3 are integers.
7. General equation: y = (3 / 5) + b * z - x / (a % 2) + PI (recall: a is an integer; the 3 and 5 constants in the equation should be left as integers initially, but explicitly type-casted as floating-point values)
-------------------------------------------------------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main (void)
{
double mass, acceleration, force;
double volume_cylinder, radius, height;
double distance;
float x1,x2,y1,y2;
int shift;
char plc, ecc;
double theta=0,sin_theta=0,cos_theta=0, tan_theta=0;
int R1,R2,R3;
double parallel_resistance;
int z=0, x=0, b=0, a=0, y=0;
/*equation 3: Character Encoding: encoded_character = (plaintext_character - 'A') + 'a' + shift*/
printf("Question 3. Character Encoding: encoded_character = (plaintext_character - 'A') + 'a' + shift. ");
printf("Please input a character: ");
scanf("%c", &plc);
printf("Please apply a value to 'shift', 'shift' is an integer: ");
scanf("%lf", &shift);
ecc = plc - 65 + 97 + shift;
printf("The encoded character is %c ", ecc);
/*equation 6: Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3)*/
printf("Question 6. Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3)");
printf("Enter the resistor's values: ");
printf("R1: ");
scanf("%lf", &R1);
printf("R2: ");
scanf("%lf", &R2);
printf("R3: ");
scanf("%lf", &R3);
parallel_resistance = 1/(1/R1+1/R2+1/R3);
printf("parallel_resistance = 1 / (1 / %lf + 1 / %lf + 1 / %lf)=%lf ",R1,R2,R3,parallel_resistance);
/*equation 7:General Equation:y = (3 / 5) + b * z - x / (a % 2) + PI */
printf("To calculate the value of equation y = (3 / 5) + b * z - x / (a %% 2) + PI, please enter the following information: ");
printf("x: ");
scanf("%lf", &x);
printf("z: ");
scanf("%lf", &z);
printf("a: ");
scanf("%d", &a);
printf("b: ");
scanf("%lf", &b);
y=(3/5)+b*z-x/(a%2)+3.1416;
printf("For the given equation y =(3 / 5) + b * z - x / (a %% 2) + PI = %lf ", y);
return 0;
}
----------------------------------------------------------------------------------
Thanks, i will rate.
Explanation / Answer
Since shift is an integer, you have to scan it with %d. Same is the case with R1, R2, and R3.
Correct code = scanf("%d", &shift);
Correct code for entering R1, R2, and R3
printf("Enter the resistor's values: ");
printf("R1: ");
scanf("%d", &R1);
printf("R2: ");
scanf("%d", &R2);
printf("R3: ");
scanf("%d", &R3);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.