Question
how would i modify this code to read in information from a file and then output into a file #include #include #include int main() {
how would i modify this code to read in information from a file and then output into a file
#include
printf("Choose from 1 to 6 from the following: "); printf("1.Ohm's Law To Find the voltage. "); printf("2.Ohm's Law To Find the current. "); printf("3.Ohm's Law To Find the resistance. "); printf("4.Voltage Divider To find the voltage accros R1. "); printf("5.Voltage Divider To find the voltage accros R2. "); printf("6.Current Divider To find the Current passing through R1. "); printf("7.Current Divider To find the Current passing through R2. "); printf("Anything else to quit. ");
scanf("%c",&ch); switch(ch) { case '1' : printf("Current Value? "); scanf("%f",¤t); printf("Resistance Value? "); scanf("%f",&resistance); result = current * resistance; printf("The voltage is %0.2f V. ",result); break; case '2' : printf(" voltage value? "); scanf("%f",&voltage); printf("Resistance value? "); scanf("%f",&resistance); result = voltage / resistance; printf("The current is %0.2f A. ",result); break; case '3' : printf("voltage value? "); scanf("%f",&voltage); printf("current Value? "); scanf("%f",¤t); result = voltage / current; printf("The resistance is %0.2f ohms. ",result);
case '4' : printf("R1 Value? "); scanf("%f",&R1); printf("R2? "); scanf("%f",&R2); printf("Voltage Value? "); scanf("%f",&voltage); result = R1*voltage/(R1+R2); printf("The voltage is %0.2f V. ",result); break;
case '5' : printf("R1 Value? "); scanf("%f",&R1); printf("R2? "); scanf("%f",&R2); printf("Voltage Value? "); scanf("%f",&voltage); result = R2*voltage/(R1+R2); printf("The voltage is %0.2f V. ",result); break; case '6' : printf("R1 Value? "); scanf("%f",&R1); printf("R2 value? "); scanf("%f",&R2); printf("current Value? "); scanf("%f",¤t); result = R2*current/(R1+R2); printf("The current is %0.2f A. ",result); break; case '7' : printf("R1 Value? "); scanf("%f",&R1); printf("R2 Value? "); scanf("%f",&R2); printf("current Value? "); scanf("%f",¤t); result = R1*current/(R1+R2); printf("The current is %0.2f A. ",result); break; break; default : exit(0); return 0;} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started