Question

Please write a code in C that will allow the user to choose to calculate voltage,...

Please write a code in C that will allow the user to choose to calculate voltage, resistance or current. Then the program will prompt the user to enter the necessary values and output the result.

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

code:

#include <stdio.h>
int main()
{
    double i,v,r;
   int ch;
    printf("1.Current\n2.Resistance\n3.Voltage\nWhat do you want to calculate(enter 1 or 2 or 3)?:");
    scanf("%d",&ch);
    if(ch==1)
    {
        printf("Enter resistance:");
        scanf("%f",&r);
        printf("Enter voltage:");
        scanf("%f",&v);
        printf("Current= %.2f",v/r);
   }
   if(ch==2)
    {
        printf("Enter current:");
        scanf("%f",&i);
        printf("Enter voltage:");
        scanf("%d",&v);
        printf("Resistance= %.2f",v/i);
   }
   if(ch==3)
    {
        printf("Enter resistance:");
        scanf("%f",&r);
        printf("Enter current:");
        scanf("%f",&i);
        printf("Current= %.2f",i*r);
   }
return 0;
}

Note: Due to some technical issues I fail to upload screenshots of output. But I can assure you best output for the above code

Add a comment
Know the answer?
Add Answer to:
Please write a code in C that will allow the user to choose to calculate voltage,...
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
  • Problem: Design and write a C language program that can be used to calculate Voltage, Current...

    Problem: Design and write a C language program that can be used to calculate Voltage, Current and Total Resistance for a Series or Parallel or a Series Parallel circuit. The program should display the main menu that contains the three types of circuit calculations that are available and then the user will be prompted to select a circuit first. After the circuit has been selected the program should then display another menu (i.e., a submenu) requesting the necessary data for...

  • C++ please no arrays! Create a program that will allow the user to enter up to...

    C++ please no arrays! Create a program that will allow the user to enter up to 50 whole values and determine the number of values entered, how many of the values were odd and how many of the values were even. Your code should contain 2 functions, a main function and a function to enter the numbers enter and count the values. Your main function should be a driver program that will call another function to count the total number...

  • Write a program in C++ to calculate the average (mean) and the standard deviation of a...

    Write a program in C++ to calculate the average (mean) and the standard deviation of a list of numbers using vectors. Your program should... Prompt for the number of values the user wishes to enter Prompt the user to enter the values one at a time for the number of requested values into a vector Calculate and display the Mean and Standard Deviation The flow of your code should be similar to: int main() { /** Prompt the user and...

  • Write a C++ program to allow an user to enter username and password, and then compare...

    Write a C++ program to allow an user to enter username and password, and then compare the entered values with the values which stored in a file called login.txt. Display an message "Login successful" if the values are matched, otherwise display "Login fail!. This program allow the user to have three times of tries, if exceeded the number of times, display a message "Number of times is exceeded, please contact administrator (Assume, the stored username is "INTI-IU and password is...

  • please code in basic c++ program Write a program that uses the following formula: n (ax...

    please code in basic c++ program Write a program that uses the following formula: n (ax - ib) i=1 Your program will prompt the user for the number of iterations for the calculation. input values for n, x, a, b, and c. n must be a positive integer, but x, a, b, and c can be any real numbers. Then it will perform the calculation and output the result. Then, it will ask the user if they would like to...

  • Write a C program that finds voltage drop and power dissipated by a resistance (R) when...

    Write a C program that finds voltage drop and power dissipated by a resistance (R) when a current (I) flows through it. Resistance and current values are given as inputs. Create a function that would find the voltage drop, and create another function that would find the power. Use these functions in your program and print the voltage drop and power dissipated on the console. The input and output values are single precision floating-point values. Comment your code.

  • Write a Python program in this Jupyter Notebook. This program will allow a user to choose...

    Write a Python program in this Jupyter Notebook. This program will allow a user to choose from a menu to print various text shapes includeing rectangle, triangle, and diamond as well as a set of numbers in a pattern. This program will allow the user to select the type, the size and/or the fill character for a shape. Your program will verify user inputs such as size for certain range specifications, depending on the shapes.

  • need help please! thanks!! C++ programming Your program should do the following Prompt the user for...

    need help please! thanks!! C++ programming Your program should do the following Prompt the user for the first number (int data type) Read the first number Prompt the user for the second number (int data type) Read the second number Write code to calculate the quotient and remainder when the first number is divided by the second number Make sure to used variables in your output statements. /* OUTPUT Enter the first number: 126 Enter the second number: 31 126...

  • Write an interactive C++ program that asks a user to input the color code of a...

    Write an interactive C++ program that asks a user to input the color code of a resistor and determines its value and tolerance Tell the user how to input the color rings “Instructions” Tell the user to input the colors one after the other After the program receives the information it will display the resistance and tolerance Output an error message if the user enters an invalid color code (no garbage values should be displayed), and ask for another input...

  • Write code that dynamically allocates an array of 20 integers, then uses a loop to allow...

    Write code that dynamically allocates an array of 20 integers, then uses a loop to allow the user to enter values for each element of the array. In C++ please, do not google, thanks!

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