Question

C code program help. I am trying to find the total parallel resistive load. This is...

C code program help.

I am trying to find the total parallel resistive load. This is what I have so far. It does run, it does ask for numbers. But it doesn't calculate. It just comes out "The parallel is: 0.00". I have tried 3, 4, 5 and 3.2, 4.3, 5.4. Still only shows 0.00. I have tried several combinations of putting different data types in both main.c and the rest of it.

Any help or ideas would be helpful. Thank you.

(There are other questions that were in the code but I have deleted it before posting. So there might be some random code still left in here. But I tried really hard to comment out everything but the part I was working on. )

#define   _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{

//Resistance Problem 1
   double resistor1 = 0.0, resistor2 = 0.0, resistor3 = 0.0;
   double inverse_resistance = 0.0;
   double parallel_resistance = 0.0;
   resistor1 = get_number5_r1();
   resistor2 = get_number6_r2();
   resistor3 = get_number7_r3();
   inverse_resistance = get_inverse_resistance(resistor1, resistor2, resistor3);
   parallel_resistance = calculate_parallel_resistance(inverse_resistance);
   display_parallel_resistance(parallel_resistance);
}

//Total Resistance Baggage
/*int get_number5_r1(void)
{
   double resistor1 = 0.0;
   printf("Please enter the resistance of the first resistor: \n");
   scanf("%lf", &resistor1);

   return resistor1;
}
int get_number6_r2(void)
{
   double resistor2 = 0.0;
   printf("Please enter the resistance of the second resistor: \n");
   scanf("%lf", &resistor2);

   return resistor2;
}
int get_number7_r3(void)
{
   double resistor3 = 0.0;
   printf("Please enter the resistance of the third resistor: \n");
   scanf("%lf", &resistor3);

   return resistor3;
}

//I split the next two up because I thought that it would help fix the remainder problem.
//As of now it has not.

get_inverse_resistance(double resistor1, double resistor2, double resistor3)
{
   double inverse_resistance = 0.0;
   inverse_resistance = ((1.0 / resistor1) + (1.0 / resistor2) + (1.0 / resistor3));
  
   return &inverse_resistance;
}
calculate_parallel_resistance(double inverse_resistance)
{
   double parallel_resistance = 0.0;
   parallel_resistance = (double)((1.0 / inverse_resistance));

   return (double)parallel_resistance;
}
display_parallel_resistance (double parallel_resistance)
{
   printf("The parallel resistance is: %.2lf\n\n\n", parallel_resistance);
}*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double get_inverse_resistance(double resistor1, double resistor2, double resistor3)

{

double inverse_resistance = 0.0;

inverse_resistance = ((1.0 / resistor1) + (1.0 / resistor2) + (1.0 / resistor3));

return inverse_resistance;

}

double calculate_parallel_resistance(double inverse_resistance)

{

double parallel_resistance = 0.0;

parallel_resistance = (double)((1.0 / inverse_resistance));

return (double)parallel_resistance;

}

void display_parallel_resistance (double parallel_resistance)

{

printf("The parallel resistance is: %.2lf\n\n\n", parallel_resistance);

}

//Total Resistance Baggage

double get_number5_r1(void)

{

double resistor1 = 0.0;

printf("Please enter the resistance of the first resistor: \n");

scanf("%lf", &resistor1);

return resistor1;

}

double get_number6_r2(void)

{

double resistor2 = 0.0;

printf("Please enter the resistance of the second resistor: \n");

scanf("%lf", &resistor2);

return resistor2;

}

double get_number7_r3(void)

{

double resistor3 = 0.0;

printf("Please enter the resistance of the third resistor: \n");

scanf("%lf", &resistor3);

return resistor3;

}


int main(void)

{

//Resistance Problem 1

double resistor1 = 0.0, resistor2 = 0.0, resistor3 = 0.0;

double inverse_resistance = 0.0;

double parallel_resistance = 0.0;

resistor1 = get_number5_r1();

resistor2 = get_number6_r2();

resistor3 = get_number7_r3();

inverse_resistance = get_inverse_resistance(resistor1, resistor2, resistor3);

parallel_resistance = calculate_parallel_resistance(inverse_resistance);

display_parallel_resistance(parallel_resistance);

}

==========================================================================================
SEE OUTPUT

PLEASE COMMENT if there is any concern.

=============================

Add a comment
Know the answer?
Add Answer to:
C code program help. I am trying to find the total parallel resistive load. This is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • I am told to find the median of random inputs using if statements in C #include...

    I am told to find the median of random inputs using if statements in C #include <stdio.h> #include <stdlib.h> int main() { double a, b, c, d; scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &c); if (a<b && b<c) d = b; printf("%.0f\n", d); else if (b<a && a<c) d = a; printf("%.0f\n", d); else d = c; printf("%.0f\n", d); return 0; } That is my code, I keep getting an error for the else if and else saying there is no...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • i'm having trouble making an else statement that will allow the program to add and output...

    i'm having trouble making an else statement that will allow the program to add and output the average the valid numbers inputed into the program. Here's my output: Enter Score 1:36 Enter Score 2:-1 Invalid Input Enter Score 2:89.5 Enter Score 3:42 Enter Score 4:66.3 Enter Score 5:93 You entered: 36.000000, 89.500000, 42.000000, 66.300000, 93.000000 Total Score: 362.800000 Average Score: 72.560000 Max Score: 93.000000 Min Score: 36.000000 Here's my code: #include <stdio.h> int main(void) { double score[5]; double min; double...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • I am trying to write C programming code and output will be as below but I...

    I am trying to write C programming code and output will be as below but I donno how to get the result analysis part. help me to add the 2nd part with my code: here is my code below: #include <stdio.h> #define MAX 100 struct studentMarkVariable{ int id; float marks; }; void getData(struct studentMarkVariable arrs[]); void show(struct studentMarkVariable arrs[]); int main() { printf ("####### Marks Analyzer V3.0 ####### \n");       struct studentMarkVariable arrs[MAX];     getData(arrs);     show(arrs); return 0; }...

  • I am trying to figure out why my C code is outputting "exited, segmentation fault". The...

    I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT